Skip to content

Commit a7a6941

Browse files
committed
[ZEPPELIN-6375] Add auto-reconnect for abnormal WebSocket closures in new UI
### What is this PR for? This PR adds automatic WebSocket reconnection for non-normal connection closures to the Angular UI (`zeppelin-web-angular`), matching the behavior of the legacy AngularJS UI. Previously, when the WebSocket connection was closed abnormally (e.g., due to network issues, server timeouts, or browser tab throttling), the Angular UI would not attempt to reconnect, leaving users with a broken connection and requiring a manual page refresh. This fix monitors WebSocket close events and automatically reconnects when the close code is not 1000 (Normal Closure). ### What type of PR is it? Bug Fix ### Todos * [x] - Add reconnection logic for non-normal close codes ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-6375 - Another related issue: https://issues.apache.org/jira/browse/ZEPPELIN-6374 ### How should this be tested? 1. Start Zeppelin server locally 2. Open a notebook in the new UI 3. Test abnormal closure scenarios: - e.g., **Tab throttling**: Leave the tab inactive for 2+ minutes (If you could watch the logs for `ZeppelinServer`, then you could check the timeout disconnect right away.). 4. Verify that: - WebSocket automatically reconnects after idle timeout. - Console shows "WebSocket closed unexpectedly. Reconnecting...". - Notebook operations work after reconnection and connection status icon remain green color. ### Questions: * Does the license files need to update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Closes #5116 from tbonelee/fix-websocket. Signed-off-by: ChanHo Lee <[email protected]> (cherry picked from commit 3e56d81) Signed-off-by: ChanHo Lee <[email protected]>
1 parent 61f7d98 commit a7a6941

File tree

1 file changed

+7
-1
lines changed
  • zeppelin-web-angular/projects/zeppelin-sdk/src

1 file changed

+7
-1
lines changed

zeppelin-web-angular/projects/zeppelin-sdk/src/message.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class Message {
5252
private ticket?: Ticket;
5353
private uniqueClientId = Math.random().toString(36).substring(2, 7);
5454
private lastMsgIdSeqSent = 0;
55+
private readonly normalCloseCode = 1000;
5556

5657
constructor() {
5758
this.open$.subscribe(() => {
@@ -60,10 +61,15 @@ export class Message {
6061
this.pingIntervalSubscription.unsubscribe();
6162
this.pingIntervalSubscription = interval(1000 * 10).subscribe(() => this.ping());
6263
});
63-
this.close$.subscribe(() => {
64+
this.close$.subscribe(event => {
6465
this.connectedStatus = false;
6566
this.connectedStatus$.next(this.connectedStatus);
6667
this.pingIntervalSubscription.unsubscribe();
68+
69+
if (event.code !== this.normalCloseCode) {
70+
console.log('WebSocket closed unexpectedly. Reconnecting...');
71+
this.connect();
72+
}
6773
});
6874
}
6975

0 commit comments

Comments
 (0)