[PR #5989] fix(realtime): track manual vs server-initiated disconnects #5447

Open
opened 2026-03-17 02:53:24 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5989
Author: @mahmoodhamdi
Created: 3/13/2026
Status: 🔄 Open

Base: mainHead: fix/realtime-disconnect-manual-flag


📝 Commits (2)

  • 99d9001 fix(realtime): track manual vs server-initiated disconnects
  • cd90fb9 fix(realtime): avoid setting manualDisconnect in error handler

📊 Changes

3 files changed (+14 additions, -7 deletions)

View changed files

📝 packages/hoppscotch-common/src/helpers/realtime/SIOConnection.ts (+6 -2)
📝 packages/hoppscotch-common/src/helpers/realtime/SSEConnection.ts (+3 -3)
📝 packages/hoppscotch-common/src/helpers/realtime/WSConnection.ts (+5 -2)

📄 Description

Description

Closes #5987

Socket.IO, WebSocket, and SSE connections all hardcode manual: true on disconnect/stop events, making it impossible for the UI to distinguish between user-initiated disconnects and unexpected server-side connection drops.

MQTT already handles this correctly with a manualDisconnect flag — this PR brings the same pattern to the other three realtime protocols.

Changes

SIOConnection.ts & WSConnection.ts:

  • Added a private manualDisconnect = false flag
  • Set it to true only in the user-facing disconnect() method
  • Read and reset the flag in the disconnect/close event handler

SSEConnection.ts:

  • Added a manual parameter to stop() (defaults to true for backward compatibility with the existing UI call sse.value.stop())
  • Internal error handler now calls this.stop(false) to correctly mark error-triggered stops as non-manual

Testing

  • All 680 existing tests in hoppscotch-common pass
  • Full typecheck passes across all packages
  • Lint passes (0 errors, only pre-existing warnings)
  • Follows the exact same pattern already used and tested in MQTTConnection.ts

Summary by cubic

Fixes realtime disconnect events to correctly flag user-initiated vs server-side drops, so the UI can distinguish intentional disconnects from unexpected failures. Aligns Socket.IO, WebSocket, and SSE with the existing MQTT pattern.

  • Bug Fixes
    • Socket.IO/WebSocket: add manualDisconnect; set only in disconnect(), read/reset in the close handler; error handlers now close sockets directly without toggling the flag.
    • SSE: add stop(manual = true); internal error path calls stop(false) to mark non-manual stops.
    • Backward compatible: default stop() behavior unchanged for existing UI calls.

Written for commit cd90fb9958. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5989 **Author:** [@mahmoodhamdi](https://github.com/mahmoodhamdi) **Created:** 3/13/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/realtime-disconnect-manual-flag` --- ### 📝 Commits (2) - [`99d9001`](https://github.com/hoppscotch/hoppscotch/commit/99d9001d70809d1850f509ccf807aa09d0ccaefb) fix(realtime): track manual vs server-initiated disconnects - [`cd90fb9`](https://github.com/hoppscotch/hoppscotch/commit/cd90fb9958b514e85e42d236c0f70b0e2996aa2d) fix(realtime): avoid setting manualDisconnect in error handler ### 📊 Changes **3 files changed** (+14 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/helpers/realtime/SIOConnection.ts` (+6 -2) 📝 `packages/hoppscotch-common/src/helpers/realtime/SSEConnection.ts` (+3 -3) 📝 `packages/hoppscotch-common/src/helpers/realtime/WSConnection.ts` (+5 -2) </details> ### 📄 Description ### Description Closes #5987 Socket.IO, WebSocket, and SSE connections all hardcode `manual: true` on disconnect/stop events, making it impossible for the UI to distinguish between user-initiated disconnects and unexpected server-side connection drops. MQTT already handles this correctly with a `manualDisconnect` flag — this PR brings the same pattern to the other three realtime protocols. ### Changes **SIOConnection.ts & WSConnection.ts:** - Added a `private manualDisconnect = false` flag - Set it to `true` only in the user-facing `disconnect()` method - Read and reset the flag in the disconnect/close event handler **SSEConnection.ts:** - Added a `manual` parameter to `stop()` (defaults to `true` for backward compatibility with the existing UI call `sse.value.stop()`) - Internal error handler now calls `this.stop(false)` to correctly mark error-triggered stops as non-manual ### Testing - All 680 existing tests in hoppscotch-common pass - Full typecheck passes across all packages - Lint passes (0 errors, only pre-existing warnings) - Follows the exact same pattern already used and tested in `MQTTConnection.ts` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes realtime disconnect events to correctly flag user-initiated vs server-side drops, so the UI can distinguish intentional disconnects from unexpected failures. Aligns `Socket.IO`, `WebSocket`, and `SSE` with the existing MQTT pattern. - **Bug Fixes** - Socket.IO/WebSocket: add `manualDisconnect`; set only in `disconnect()`, read/reset in the close handler; error handlers now close sockets directly without toggling the flag. - SSE: add `stop(manual = true)`; internal error path calls `stop(false)` to mark non-manual stops. - Backward compatible: default `stop()` behavior unchanged for existing UI calls. <sup>Written for commit cd90fb9958b514e85e42d236c0f70b0e2996aa2d. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5447
No description provided.