n8n-io / n8n

Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.
https://n8n.io
Other
45.7k stars 6.36k forks source link

Trigger starts wrong Workflow #1838

Closed erbg closed 1 year ago

erbg commented 3 years ago

Describe the bug We use N8n to send out different notifications based on Messages comming in from different AMQP topics. We are facing a problem, that in some case the wrong Workflow is triggered, example:

Workflow 1: Trigger come from Topic A, send out an E-Mail Workflow 2: Trigger comes from Topic B, calls an API

Actualy it happens, that a Topic A calls Workflow 2 and calls an API.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior The correct Workflow is started

Environment (please complete the following information):

Additional context Add any other context about the problem here.

It seams to me that the triggers on N8N are always called on the "nodeType" class, with is cached in the workflow class: https://github.com/n8n-io/n8n/blob/972561416c5cd87757bae787438610822e8292d8/packages/workflow/src/Workflow.ts#L809

janober commented 3 years ago

I am "sadly" not able to reproduce this. For me, it works totally fine. If I have two workflows and each of them has an AMQP Trigger node, one listing to "test" the other one to "test2", I activate that workflows and send messages to either "test" or "test2" it ALWAYS starts the correct workflow.

For each trigger node that gets executed the following function gets started (with the appropriate parameters) and keeps on running till it gets deactivated: https://github.com/n8n-io/n8n/blob/master/packages/nodes-base/nodes/Amqp/AmqpTrigger.node.ts#L133

erbg commented 3 years ago

I have added some more Debug information and will keep this issue under control. As i wrote, it is not happening all the time, so it is realy difficult to reproduce.

janober commented 3 years ago

Great, thanks a lot! If you find anything please get back to me!

erbg commented 3 years ago

It happend again.

As you can see we have actually 4 diffenent Topic subscriptions where n8n is listening.

If I sent a new message to the Topic the Filters of the Subscriptions send the message in the correct Subscription. Actually I duplicated the Subscriptions n8n-na and n8n-so with the -backup name so that we now where the message was delivered to.

image

As you can see, actulay the message was sended to n8n-so, but on n8n the message con on the subscription n8n-na - and so it triggered the wrong workflow.

image

Here is the change I made to the AmqpTrigger.node.ts file for debugging purpose.

container.on('message', (context: EventContext) => {
            console.log("New Message:", subscription, "Options:", context.receiver?.options, self.getWorkflow().name);

As you can see the EventContext is also wrong, there could be a problem on the rhea container site or in n8n.

erbg commented 3 years ago

For the moment i changed my setup and moved everything to one only AMQP Trigger that then decides with workflow to start.

Joffcom commented 1 year ago

Hey @erbg,

As you have worked around this do you have any objections to me closing this one for now?

erbg commented 1 year ago

Ok for me.

Joffcom commented 1 year ago

Hey @erbg,

Perfect in that case I will get this one marked as closed for now 🙌🏻