Ensure local ws connections are closed on disconnect #255
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes FlowFuse/flowfuse#3751
When the device agent tunnel connection is dropped, we weren't closing down the local ws connection to Node-RED - however the platform side does tidy up the corresponding editor->platform connections. This meant that when the tunnel reconnects, the editors create new ws connections which in turn create new ws connections to Node-RED in the agent. This causes duplicate messages to be sent back over the proxy to the connected clients.
This fixes it by ensuring the local ws connections are closed if the tunnel closes.
Whilst debugging, it was also observed that if a tunnel fails to connect, we wouldn't retry the connection; the retry logic was only be applied if a connected socket is dropped unexpectedly.
This fixes that by not treating 'ECONNREFUSED' as a fatal error as it did before.
I've also increased the default reconnect timeout to 1.5s from 0.5s to give the remove end a bit more time to recover, with out any real impact on the user experience.