FlowFuse / node-red-dashboard

https://dashboard.flowfuse.com
Apache License 2.0
161 stars 35 forks source link

Event handlers (in custom ui nodes) not receiving widget notifications after socket reconnect #913

Open omrid01 opened 1 month ago

omrid01 commented 1 month ago

Current Behavior

this may be related to #909. When the Node-red server is restarted (or after deploy/restart flows in the editor), the connection to all dashboard clients is terminated and then automatically restored. However, after the reconnect, the widget can receive new messages from the server node, but some of the widget notifications to the server node's onSocket listener may stop working. Refreshing the client page solves the issue.

Expected Behavior

After socket connection restoration all widget-node communication (in both directions) should resume properly.

Steps To Reproduce

  1. Take a clean Dashboard 2.0 ui node, for example ui-example
  2. Implement a widget-to-node notification mechanism, e.g.:

In widget:

this.$socket.emit('myCustomEvent'+this.id, this.id, msg)

In server node:

onSocket: {
     ['myCusomEvent'+node.id]: function (conn, id, msg) {console.log("Hello from "+conn)}
  1. Open 3 clients, verify that they all succeed in sending the above notification to the server node
  2. Restart the Node-red server process, or deploy/restart flows in the editor, wait for all clients to reconnect
  3. Try again to send notifications from all clients - usually some of them will fail (nothing arriving on server node)

Environment

Have you provided an initial effort estimate for this issue?

I have provided an initial effort estimate

joepavitt commented 1 month ago

This is definitely a pressing issue we have, but will take some time to investigate

omrid01 commented 1 month ago

Until fixed, I will be putting a temporary workaround, where the server node (upon start), waits 1-2 seconds, and then sends a special command to all clients telling them to reload themselves.