Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Make senderId required for all command messages #7252

Merged

Conversation

flipswitchingmonkey
Copy link
Contributor

all commands sent between main instance and workers need to contain a server id to prevent senders from reacting to their own messages, causing loops

this PR makes sure all sent messages contain a sender id by default as part of constructing a sending redis client.

@github-actions
Copy link
Contributor

Great PR! Please pay attention to the following items before merging:

Files matching packages/**:

  • If fixing bug, added test to cover scenario.
  • If addressing forum or Github issue, added link to description.

Files matching packages/**/*.ts:

  • Added unit tests to cover new or updated functionality.

Make sure to check off this list before asking for review.

@flipswitchingmonkey flipswitchingmonkey marked this pull request as ready for review September 25, 2023 15:44
@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Sep 25, 2023
protected server?: AbstractServer;

async init(): Promise<void> {
async init(instanceType?: N8nInstanceType): Promise<void> {
Copy link
Member

@netroy netroy Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this an abstract property in BaseCommand? then each command can define this value before the constructor,and we don't need to wait until init to determine this value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved setting the instance type and queue mode id into the constructors

packages/cli/src/config/schema.ts Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

Attention: 38 lines in your changes are missing coverage. Please review.

Comparison is base (77d6e3f) 32.93% compared to head (624566a) 32.93%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7252   +/-   ##
=======================================
  Coverage   32.93%   32.93%           
=======================================
  Files        3355     3355           
  Lines      200130   200139    +9     
  Branches    21944    21938    -6     
=======================================
+ Hits        65910    65914    +4     
- Misses     133109   133117    +8     
+ Partials     1111     1108    -3     
Files Coverage Δ
packages/cli/src/commands/worker.ts 25.60% <100.00%> (+0.72%) ⬆️
packages/cli/src/config/schema.ts 81.81% <ø> (ø)
...li/src/eventbus/MessageEventBus/MessageEventBus.ts 42.39% <100.00%> (+2.65%) ⬆️
.../MessageEventBusWriter/MessageEventBusLogWriter.ts 54.36% <100.00%> (ø)
.../cli/src/services/redis/RedisServiceBaseClasses.ts 70.00% <100.00%> (+5.71%) ⬆️
...s/cli/src/services/redis/RedisServiceListSender.ts 50.00% <100.00%> (-2.95%) ⬇️
.../src/services/redis/RedisServicePubSubPublisher.ts 61.11% <100.00%> (+2.28%) ⬆️
packages/cli/src/AbstractServer.ts 48.57% <0.00%> (ø)
packages/cli/src/Server.ts 0.00% <0.00%> (ø)
packages/cli/src/services/orchestration.service.ts 62.85% <50.00%> (+7.53%) ⬆️
... and 7 more

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@netroy netroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks 🙏🏽

const license = Container.get(License);
await license.init(this.instanceId, instanceType);
await license.init(this.instanceId, this.instanceType ?? 'main');
Copy link
Member

@netroy netroy Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was why I wanted to create a ServerCommand class, so that all cli commands don't end up using instanceType='main'. But that can be fixed in another PR.

@@ -65,6 +66,12 @@ export class Start extends BaseCommand {

protected server = new Server();

constructor(argv: string[], cmdConfig: IConfig) {
super(argv, cmdConfig);
this.setInstanceType('main');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I suggested using an abstract property, I meant that we can then overwrite the property in the derived class without having to override the constructor like this.
but for now this work fine.

Comment on lines 23 to +30
case 'reloadLicense':
await Container.get(License).reload();
// at this point in time, only a single main instance is supported, thus this
// command _should_ never be caught currently (which is why we log a warning)
LoggerProxy.warn(
'Received command to reload license via Redis, but this should not have happened and is not supported on the main instance yet.',
);
// once multiple main instances are supported, this command should be handled
// await Container.get(License).reload();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code like this should stay in a WIP branch, instead of being merged in master.

@@ -12,7 +12,7 @@ export type RedisServiceCommand =
* @field payload: Optional arguments to be sent with the command.
*/
type RedisServiceBaseCommand = {
senderId?: string;
senderId: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we perhaps remove this from here? this property gives an impression that whenever we are publishing a command, we can include a senderId, which isn't true. not to mention, we have to do Omit<RedisServiceCommandObject, 'senderId'> to block people from adding a senderId in the payload.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could go the inverse and remove it here and have another interface with added senderId

@cypress
Copy link

cypress bot commented Sep 26, 2023

2 flaky tests on run #2271 ↗︎

0 242 3 0 Flakiness 2

Details:

🌳 pay-847-make-senderid-required-for-all-redis-messages 🖥️ browsers:node18.12....
Project: n8n Commit: 624566a251
Status: Passed Duration: 08:13 💡
Started: Sep 26, 2023 9:53 AM Ended: Sep 26, 2023 10:02 AM
Flakiness  2-credentials.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Credentials > should create a new credential using Add Credential button Output Screenshots Video
Flakiness  28-debug.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Debug > should be able to debug executions Output Screenshots Video

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@github-actions
Copy link
Contributor

✅ All Cypress E2E specs passed

@@ -64,6 +67,7 @@ export class License {
loadCertStr: async () => this.loadCertStr(),
saveCertStr,
deviceFingerprint: () => instanceId,
onFeatureChange,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't we want to set offlineMode to true on workers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const offlineMode = !isMainInstance;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, sorry, I didn't realize that GitHub was hiding these lines 🤦‍♂️

@flipswitchingmonkey flipswitchingmonkey merged commit 4b01428 into master Sep 26, 2023
26 checks passed
@flipswitchingmonkey flipswitchingmonkey deleted the pay-847-make-senderid-required-for-all-redis-messages branch September 26, 2023 11:58
This was referenced Sep 27, 2023
netroy added a commit that referenced this pull request Sep 28, 2023
# [1.9.0](https://github.com/n8n-io/n8n/compare/n8n@1.8.0...n8n@1.9.0)
(2023-09-28)


### Bug Fixes

* **Airtable Node:** Attachments field type fix
([#7227](#7227))
([2af967c](2af967c))
* **core:** Change WorkflowHistory nodes/connections columns to be json
([#7282](#7282))
([a80abad](a80abad))
* **core:** Fix binary data manager check on pruning
([#7251](#7251))
([484035e](484035e))
* **core:** Fix missing execution ID in webhook-based workflow producing
binary data ([#7244](#7244))
([33991e9](33991e9))
* **core:** Handle filename* with quotes in Content-Disposition header
([#7229](#7229))
([67b985f](67b985f))
* **core:** Make DNS resolution order configurable
([#7272](#7272))
([5b3121c](5b3121c))
* **core:** Make senderId required for all command messages
([#7252](#7252))
([4b01428](4b01428))
* **core:** Prevent executions from displaying Running status
incorrectly ([#7261](#7261))
([861cac5](861cac5))
* **core:** Use consistent timezone-aware timestamps in postgres
([#6948](#6948))
([0132514](0132514)),
closes [#2178](#2178)
[#2810](#2810)
[#3855](#3855)
[#2813](#2813)
* **editor:** Add debug feature docs link
([#7240](#7240))
([4614e1e](4614e1e))
* **editor:** Fix SQL editor issue
([#7236](#7236))
([647fc6c](647fc6c))
* **editor:** Ensure new Set node is on top of search list
([#7215](#7215))
([2491ccf](2491ccf))
* **editor:** Forbid password reset when cloud account is limited in the
number of users [7188](#7188)
([303bc8e](303bc8e))
* **HTTP Request Node:** Add suggestion how to fix '429 - too many
requests' errors ([#7293](#7293))
([0bc33b1](0bc33b1))
* **Item Lists Node:** Concatenate operation pairedItems fix
([#7286](#7286))
([cde23a1](cde23a1))
* **Respond to Webhook Node:** JSON output from expression fix
([#7294](#7294))
([8bc369d](8bc369d))


### Features

* Add onboarding flow
([#7212](#7212))
([01e9340](01e9340))
* **core:** Add secrets provider reload and refactor
([#7277](#7277))
([53a7502](53a7502))
* **core:** Add Tournament as the new default expression evaluator
([#6964](#6964))
([bf74f09](bf74f09))
* **core:** Initial workflow history API
([#7234](#7234))
([0083a9e](0083a9e))
* **core:** Introduce object store service
([#7225](#7225))
([fa84545](fa84545))
* **editor:** Add user cloud ID to telemetry
[#7232](#7232)
([60c152d](60c152d))
* **editor:** Rework banners framework and add email confirmation banner
([#7205](#7205))
([b0e98b5](b0e98b5))
* **MISP Node:** Update credential to support HTTP Request node
([#7268](#7268))
([e4c302c](e4c302c))


### Performance Improvements

* **core:** Skip unneeded calls on every pruning cycle
([#7260](#7260))
([db01164](db01164))

Co-authored-by: netroy <netroy@users.noreply.github.com>
@janober
Copy link
Member

janober commented Sep 28, 2023

Got released with n8n@1.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants