Skip to content

fix: absorb late socket errors after cleanup#23

Open
alexx-ftw wants to merge 1 commit into
nicobailon:mainfrom
alexx-ftw:fix/socket-error-guard
Open

fix: absorb late socket errors after cleanup#23
alexx-ftw wants to merge 1 commit into
nicobailon:mainfrom
alexx-ftw:fix/socket-error-guard

Conversation

@alexx-ftw
Copy link
Copy Markdown

Summary

  • keep a permanent socket error listener in IntercomClient.connect() so late read errors after cleanup/destroy cannot crash the Pi process
  • add a regression test that simulates an initial ECONNRESET, verifies cleanup leaves one guard listener, and confirms a later ECONNRESET does not throw
  • include the new client regression test in npm test

Why

A real Pi session crashed on Node.js v24.14.0 with:

node:events:486
      throw er; // Unhandled 'error' event
Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:216:20)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)

cleanupSocketListeners() removes the normal socket error handler during disconnect/error cleanup. If Node emits a late socket error while/after socket.destroy() completes, no listener remains and the process crashes. The permanent guard only absorbs errors that would otherwise be unhandled; normal error handling still runs through the existing handlers before cleanup.

Verification

  • npm install --ignore-scripts
  • npm test → 37 passing tests
  • independent review: no Critical/Important/Minor findings

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