Skip to content

call done after ws disconnects - #3531

Merged
Steve-Mcl merged 3 commits into
node-red:masterfrom
Steve-Mcl:ws-status
Apr 19, 2022
Merged

Steve-Mcl merged 3 commits into
node-red:masterfrom
Steve-Mcl:ws-status

Conversation

@Steve-Mcl

Copy link
Copy Markdown
Contributor

fixes #3527

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

As discussed in #3527 ...

this issue is *mostly a visual problem. (some internal state is modified by the old sockets disconnect event)

I can see why this happens ...

restarting flows re-creates the node
the newly created websocket is opened - causing the CONNECTED status
then the previous websocket reports it has closed - causing the DISCONNECTED status

chrome_i2GPcRyAeo

Proposed changes

Monitor the ws readyState using a 20ms interval & call done() once readyState == closed OR a MAX of 1000ms (whichever comes first)?

e.g...

        node.on("close", function(done) {
            node.closing = true;
            node.server.close();
            //wait 20*50 (1000ms max) for ws to close
            const closeMonitorInterval = 20;
            let closeMonitorCount = 50;
            let si = setInterval(() => {
                if(node.server.readyState === ws.CLOSED || closeMonitorCount <= 0) {
                    clearInterval(si);
                    return done();
                }
                closeMonitorCount--;
            }, closeMonitorInterval);
        }

Result - now the flows stop waits for ws disconnection...

chrome_x5usA8iH13

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run grunt to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

@coveralls

coveralls commented Apr 14, 2022 •

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.02%) to 68.617% when pulling 8df53e4 on Steve-Mcl:ws-status into 0aa80d8 on node-red:master.

@Steve-Mcl
Steve-Mcl requested review from dceejay and knolleary April 14, 2022 21:27
@dceejay

dceejay commented Apr 15, 2022

Copy link
Copy Markdown
Member

👍

Steve-Mcl and others added 2 commits April 19, 2022 10:30
Co-authored-by: Nick O'Leary <nick.oleary@gmail.com>
@Steve-Mcl
Steve-Mcl merged commit e092f41 into node-red:master Apr 19, 2022
@Steve-Mcl
Steve-Mcl deleted the ws-status branch April 19, 2022 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebSocket "Connect to" nodes display "disconnected" while being connected

5 participants