Skip to content

fix(websocket): auto-restart after abnormal local close (pong timeout)#231

Open
krasnyt wants to merge 1 commit into
Smarteon:masterfrom
krasnyt:fix/reconnect-on-pong-timeout
Open

fix(websocket): auto-restart after abnormal local close (pong timeout)#231
krasnyt wants to merge 1 commit into
Smarteon:masterfrom
krasnyt:fix/reconnect-on-pong-timeout

Conversation

@krasnyt

@krasnyt krasnyt commented May 22, 2026

Copy link
Copy Markdown

Problem

With setAutoRestart(true) the client fails to reconnect when the miniserver stops responding to websocket pings (a "frozen" connection). The connection stays dead until the application is restarted manually, even though auto-restart is enabled.

Root cause

When the remote end stops answering pongs, the underlying Java-WebSocket ConnectionLostChecker closes the socket locally with code 1006 (ABNORMAL_CLOSE):

LoxoneWebsocketClient - Closed by local end because of 1006:
The connection was closed because the other endpoint did not respond with a pong in time.

In LoxoneWebsocketClient.onClose() the restart is gated behind remote == true:

if (remote && code != CloseFrame.NEVER_CONNECTED) {
    ws.autoRestart();
}

A clean remote close (1000) recovers fine, but a 1006 local close — the most common real "frozen connection" case — never schedules a restart.

Fix

Also restart on an abnormal local close (1006):

if (code != CloseFrame.NEVER_CONNECTED && (remote || code == CloseFrame.ABNORMAL_CLOSE)) {
    ws.autoRestart();
}

A deliberate LoxoneWebSocket.close() goes through closeBlocking() and produces a NORMAL (1000) local close, so intentional shutdowns are still excluded and won't trigger a restart.

Tests

LoxoneWebsocketClientTest now covers three cases:

  • remote close → restart
  • abnormal local close (1006) → restart
  • deliberate local close (1000) → no restart

When the miniserver stops answering websocket pings, the underlying
Java-WebSocket ConnectionLostChecker closes the socket locally with code
1006 (ABNORMAL_CLOSE). onClose() only scheduled an auto-restart when
remote == true, so this "frozen connection" case never reconnected even
with autoRestart enabled, leaving the connection dead until the app was
restarted manually.

Also trigger autoRestart() on an abnormal local close (1006). A
deliberate LoxoneWebSocket.close() produces a NORMAL (1000) local close,
so intentional shutdowns remain excluded.
@krasnyt

krasnyt commented Jun 8, 2026

Copy link
Copy Markdown
Author

hi @jimirocks , would you have time to have a look? thanks!

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.

1 participant