fix(streams): use event-based reconnection in mdns-ws provider#2514
Open
dirkwa wants to merge 1 commit intoSignalK:masterfrom
Open
fix(streams): use event-based reconnection in mdns-ws provider#2514dirkwa wants to merge 1 commit intoSignalK:masterfrom
dirkwa wants to merge 1 commit intoSignalK:masterfrom
Conversation
connectClient() relied on the one-shot Promise from client.connect().
When the initial connection failed (e.g. ENETUNREACH because the remote
device hasn't booted yet), the Promise rejected and the setup logic
(provider status, subscriptions, remoteSelf mapping) never ran — even
after the underlying @signalk/client Connection successfully reconnected.
Switch from Promise-based (.then/.catch) to persistent event listeners:
- client.on('connect') fires on every successful connection, not just
the first, ensuring subscriptions and status are always set up
- client.on('disconnect') updates provider status on connection loss
- client.on('error') reports connection errors to the dashboard
fixes SignalK#2513
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The mdns-ws WebSocket provider failed to reconnect when the remote server was temporarily unreachable (e.g. ENETUNREACH during a simultaneous reboot of both devices).
connectClient()relied on the one-shot Promise returned byclient.connect(). When the initial connection failed, the Promise rejected and the.then()block — which sets up provider status, subscriptions, and remoteSelf context mapping — never executed. Even though the underlying@signalk/clientConnection successfully reconnected later via its internalbackOffAndReconnect()mechanism, the setup logic was skipped permanently.The fix replaces the Promise-based pattern with persistent event listeners:
client.on('connect')runs on every successful connection (initial + reconnections), ensuring subscriptions and provider status are always set upclient.on('disconnect')updates provider status when the connection dropsclient.on('error')reports connection errors to the dashboardTesting
Automated tests — 4 new integration tests in
mdns-ws.test.tsusing a real WebSocket server:$sourceannotationManual tests against a live Signal K server (localhost:4000):
connectevent fires on initial connection and updates provider statusdisconnectevent, followed by automatic reconnection with a secondconnecteventerrorevents with exponential backoff retries (250ms → 500ms → 750ms → 1000ms), confirming the client keeps retrying until the remote becomes availablefixes #2513