MQTT Trigger connections problem

Describe the problem/error/question

If MQTT Trigger is launched, I see errors in the logs, the UI gives a startup error, but if you reload the workflow page, it seems to work. In case I reboot my n8n and workflow that come after workflow with mqtt trigger are not loaded…
This function has definitely worked correctly before.

What is the error message (if any)?

(node:8) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added to [MqttClient]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: n8nio/n8n:1.8.2
  • Database (default: SQLite): PostgreSQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: Ubuntu 22.04.3 LTS

Docker Compose Setup

version: "3"

networks:
  home_network:
    name: home_network
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.18.0.0/16

services:
  emqx:
    image: emqx/emqx:5.0.24
    container_name: mqtt
    volumes:
      - ./emqx/data:/opt/emqx/data
    networks:
      home_network:
        ipv4_address: 172.18.1.4
    healthcheck:
      test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
      interval: 5s
      timeout: 25s
      retries: 5

  n8n:
    image: n8nio/n8n:1.8.2
    container_name: n8n
    restart: unless-stopped
    env_file:
      - n8n.env
    volumes:
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - 127.0.0.1:5678:5678/tcp
    networks:
      home_network:
        ipv4_address: 172.18.3.2
1 Like
(node:8) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added to [MqttClient]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)

Hi @a1ekseev, I am very sorry you are having trouble.

This error isn’t related to a specific workflow unfortunately, with the node:8 suggesting it’s somewhere inside of Node.js itself. Your workflow itself doesn’t look problematic (of course not, it’s merely a trigger node).

Perhaps you can test whether this is caused by n8n starting before your MQTT broker is listening?

Also, can you confirm which problem exactly you are seeing in the UI?

Thank you!

No, the docker-compose example that I gave is just to understand my configuration, yes, there is not enough depends_on, but in the full configuration it is taken into account.

But even if we restart workflow, we still get the same errors.
The criticality is that if I restart n8n, the workflows that start after the problematic one do not start.

Hi @a1ekseev, I was able to reproduce your problem and have added this to our bug tracker for a closer look and fix. We will of course update this thread once a fix is available.

Please accept my sincere apologies for the trouble.

1 Like

Thank you for your product.
I will wait for the fix.

1 Like

I’ve same issue with MQTT trigger. I’ve tried a number of different n8n docker image tags from 1.8.2 thru 1.11.1, and I haven’t found one that works without that error message.

Not sure if it’s related, but…when I send topic message to MQTT once, in n8n, I’ll find some 40 executions listed. A third of them will show as Succedded, but the majority will show as Running and they never timeout even though I have a 10 second timeout set for the workflow.

Is it possible the workflow isn’t unsubscribing from the MQTT topic correctly when made inactive or manual listen is over? Is it somehow ending up getting multiple messages from MQTT each time and therefore spawning many executions?

I just tried changing my topic names, and the problem seems to be gone for now.

I found out more information.
Setup:
Disable workflow
Reboot server
Change the mqtt trigger topic to something completely new to avoid old mqtt subscriptions.
Activate workflow.
Send mqtt message to the new topic from another tool.

Results:
I see one execution for one message as exected. Activating and deactivating the workflow back and forth does not break it.
To break it:
Use the “Execute Workflow” button to run a test in the n8n interface, and trigger it. One execution will occur as expected. However, all future non-manual triggers will have many executions. In fact, I think the longer I sit in the manual execution mode without receiving a trigger. The larger the number of non-manual executions will occur.

I’m suspecting that during Execute Workflow for the manual test, it is sending subscription requests over and over again, without unsubscribing between. If I sit in that state waiting for a trigger for a long time, a large number of mqtt subscriptions seem to be entered and then mqtt is sending all those publications to n8n during normal operation.

By the way, I do have Clean Session toggled on in my mqtt connection settings, and I assume that’s why a server reboot is successful at ending the problem. I just can’t test the workflow without creating the issue again.

1 Like

Hello!

Is there any news on fixing the problem?

Actually yes, but it looks like this forum conversation was overlooked in the PR, so the usual “fix has been released” message was missing in this case. n8n should no longer prevent additional workflows from being activated in case the MQTT Trigger node is having trouble: fix(MQTT Trigger Node): Fix node causing a start up hang when active by valya · Pull Request #7498 · n8n-io/n8n · GitHub

The fix is available in n8n 1.12.2 and later.

1 Like

Hi

I just did the following:

  • downloaded the latest n8n docker image and fired up n8n
  • created MQTT credentials
  • created new workflow with just a MQTT trigger node
  • Clicked on “Listen for Event”

Result: The execution runs indefinitely and cannot be stopped.

I am not sure, whether this has anything to do with the phenomenon described above or whether this is a separate problem.

Hi,

I think the issue is still there. I have a 1.15.2 version and when i launch 2-3 workflows containing mqtt triggers, nothing working and i got message : “(node:66608) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 message listeners added to [MqttClient]. Use emitter.setMaxListeners() to increase limit”

Hi folks, just to clarify what was fixed here was a problem where workflows beyond the MQTT trigger workflow would not activate. This was the original problem:

workflow that come after workflow with mqtt trigger are not loaded

Problems with the MQTT setup might be a different story. Can you please confirm if such problems still persist with n8n 1.16.0 and if so, provide detailed steps on how to reproduce the problem in a new thread?

Thank you!

Done here

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.