Repository navigation
🐛 Add WS pause gating, inbound business queue budget, and extension heartbeat_ack support - #5346
Conversation
guiyanakuang
left a comment
There was a problem hiding this comment.
NEEDS FIX
The new overload path drops a clipboard push from the browser extension without a way to retry it. See the inline finding for the sender and receiver paths.
I ran 65 desktop WebSocket unit tests, 5 WebSocket authentication integration tests, all 135 extension tests, the TypeScript type check, and git diff --check. They passed. The current tests cover the receiver's 1013 close and the heartbeat ACK capability and request ID. Browser-to-desktop recovery after an overload has yet to be exercised end to end. The iOS background-to-foreground flow also needs verification after the downstream lifecycle starts calling the new pause and resume methods.
| } else { | ||
| workChannel.send(envelope) | ||
| val payloadBytes = envelope.payload.size.toLong() | ||
| if (!tryReserve(payloadBytes)) { |
There was a problem hiding this comment.
P1 — Preserve extension clipboard pushes when the queue overflows
Problem and impact
When the receiver's business queue hits either limit, this branch closes the socket with 1013 and drops the triggering PASTE_PUSH. A clipboard item copied while the desktop receiver is backed up can stay in the extension's history without ever reaching the desktop, even after the socket reconnects.
Evidence
web/src/background/service-worker.ts:247–273 sends the push through wsManager.send() without a requestId. web/src/shared/ws/ws-manager.ts:191–200 reports success after the socket write. Reconnect only reopens the socket, and the extension's HTTP sync pulls desktop history in the other direction (service-worker.ts:412–432). The receiver's overflow test confirms that the triggering envelope is never handled.
Suggestion
Use the existing correlated paste ACK for extension pushes and keep unacknowledged items pending for retry after reconnect. Cover a push dropped by 1013 in a regression test.
Confidence 95/100
Summary
Follow-up to #5345 addressing three WebSocket stability findings surfaced during CrossPaste/crosspaste-mobile#2717 review:
WebSocket pause/resume gating (
WsSessionManager,WsClientConnector,WsRouting)WsSessionManager.pause()/resume()/isAcceptingSessions()/addOnPausedListener().pause()atomically stops accepting new sessions and handshakes, cancels all in-flight handshakes inWsClientConnector, and closes active sessions viacloseAll().registerSession()returnsBoolean(rejecting and closing any late-arriving session while paused), and bothWsClientConnectorandWsRoutingrespectisAcceptingSessions()and theregisterSession()result so mobile background pause cannot race with an in-flight HTTP heartbeat or WS handshake to establish a new session.Per-session inbound business queue byte budget (
WsMessageHandler,WsMessage,WsSession)WS_MAX_PENDING_PAYLOAD_BYTES(128 MiB) andWS_MAX_PENDING_MESSAGES(256) to bound queued business payloads indispatchWsSessionMessages().CloseReason.Codes.TRY_AGAIN_LATER(1013) so the sender falls back cleanly to its existing retry / HTTP path instead of accumulating unbounded buffers in memory (and without returningWsMessageType.ERROR, which would permanently reject the paste).Browser extension
heartbeat_ackcapability andrequestIdecho (web/src/shared/ws/)WsCapability.HEARTBEAT_ACKtows-types.tsandWS_SUPPORTED_CAPABILITIESinws-auth.ts.ws-message-handler.tsto echoenvelope.requestIdinHEARTBEAT_ACKresponses (preserving omission for legacy heartbeats withoutrequestId), closing half-open probe false positives for browser extensions.Verification
./gradlew ktlintFormat && ./gradlew app:desktopTest ktlintCheck— all fast-tier tests (including new pause gating, in-flight handshake cancellation, and inbound queue budget tests) and ktlint passed.cd web && npm test && npx tsc --noEmit— all 15 Vitest files (135 tests) and TypeScript type-checking passed.