Skip to content

fix(express,node): prevent process crashes from ws frames and lock heartbeat - #64

Merged
BatLeDev merged 1 commit into
mainfrom
fix-ws-null-crash-and-locks-heartbeat
Oct 20, 2026
Merged

BatLeDev merged 1 commit into
mainfrom
fix-ws-null-crash-and-locks-heartbeat

Conversation

@BatLeDev

Copy link
Copy Markdown
Member

A bare null WebSocket frame crashed the API process, and a mongo blip on the lock heartbeat crashed every pod. Neither path goes through Express, so with no global unhandledRejection handler the rejection took the process down.

  • ws-server: a null frame passed the typeof === 'object' guard, then threw on message.channel — in the guard and again in the catch that rebuilt the error reply — so the rejection escaped the async message handler. An unauthenticated client could crash the API with a single frame, repeatably. Frame parsing/validation is now a pure parseFrame() that never throws on arbitrary input.
  • locks: the heartbeat setInterval(updateMany) was neither awaited nor caught, so a rejection (e.g. on a mongo failover) was an unhandled rejection. Guarded with .catch(internalError).

Why: either bug is a trivial, repeatable way to take the whole stack down.

Heads-up: the ws message handler was refactored (parse extracted); behaviour is unchanged and covered by new parseFrame tests. Needs a release so data-fair can bump and pick up the fix.

…artbeat

A bare "null" ws frame passed the typeof guard and then threw while
reading message.channel, both in the guard and again in the catch, so the
rejection escaped the async message handler and crashed the process. Any
unauthenticated client could send one frame to take the API down, on every
restart. Extract frame parsing/validation into a pure parseFrame() that never
throws on arbitrary input, with regression tests.

Also guard the locks heartbeat setInterval with a .catch: an un-awaited
updateMany rejection (e.g. on a mongo failover) was an unhandled rejection
that crashed every pod.
@BatLeDev
BatLeDev merged commit 07d0814 into main Oct 20, 2026
1 check passed
@BatLeDev
BatLeDev deleted the fix-ws-null-crash-and-locks-heartbeat branch October 20, 2026 07:14
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