fix(ws): surface inbound frame errors instead of silently dropping events (fixes #201) - #204
Open
Xuxchloris wants to merge 1 commit into
Open
fix(ws): surface inbound frame errors instead of silently dropping events (fixes #201)#204Xuxchloris wants to merge 1 commit into
Xuxchloris wants to merge 1 commit into
Conversation
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.
Fixes #201
Problem
Under load, the WSClient silently loses events that Feishu delivered and ACKed at the transport level: the
[ws] receive messagedebug line never appears for the dropped event, no error is logged, no disconnect fires, and the handler is never invoked.The receive path is an async
'message'listener with no error handling:Any exception (frame decode failure, malformed pong, invalid fragment metadata, fragment JSON parse failure) rejects the listener promise — the event is dropped with no log, and the unhandled rejection can crash the process.
mergeDatahad an additional silent-loss amplifier:new Array(sum)throws aRangeErrorfor invalidsum, and aseqoutside[0, sum)creates sparse holes that produce a corrupted merged buffer (soJSON.parsefails and the event is lost).Changes
ws-client/index.tscommunicate(): wrap the whole inbound-frame handler in try/catch and log failures (failed to handle inbound frame: ...) instead of dropping them silently or surfacing them as unhandled rejections.handleEventData(): catch fragment-merge failures and log them withmessage_id/trace_idso operators can reconcile.handleControlData(): guard the pongJSON.parseand log malformed payloads.ws-client/data-cache.ts: validate fragment metadata (suminteger > 0,seqin[0, sum)) before allocating/merging, so malformed metadata throws a clear error instead of corrupting the buffer.ws-client/__tests__/receive-events.ts(new): 8 tests covering decode-failure logging with connection survival, malformed fragment metadata, malformed pong, the happy path (fragmented event merges → dispatches → ACKs), andDataCache.mergeDatavalidation.Verification
npx jest --runInBand ws-client channel— 32 suites, 325 tests passing (including the 8 new ones), 0 failures.