Skip to content

fix: handle socket errors during TLS handshake in HTTP/2 push - #314

Open
gtalusan wants to merge 2 commits into
Apollon77:masterfrom
gtalusan:master
Open

gtalusan wants to merge 2 commits into
Apollon77:masterfrom
gtalusan:master

Conversation

@gtalusan

@gtalusan gtalusan commented Oct 1, 2026

Copy link
Copy Markdown

My node-red instance was dying every few days with the message:

2026-09-30 21:45:22.727 FATAL  Unhandled            Unhandled error detected: Client network socket disconnected before secure TLS connection was established
  at TLSSocket.onConnectEnd (node:internal/tls/wrap:1820:19)
  at TLSSocket.emit (node:events:526:24)
  at endReadableNT (node:internal/streams/readable:1757:12)
  at process.processTicksAndRejections (node:internal/process/task_queues:90:21)

Traced it to node-red-contrib-alexa-remote2-applestrudel with a global socket tracker and these were the responsible sockets:

  2026-10-01T01:45:21.541Z end TLSSocket remote=44.199.80.228:443
        at Object.connect (node:internal/tls/wrap:1895:13)
        at Object.connect (node:internal/http2/core:3694:22)
        at /data/node_modules/alexa-remote2/alexa-http2push.js:140:37
        at /data/node_modules/alexa-remote2/alexa-remote.js:561:21
  2026-10-01T01:45:21.543Z close TLSSocket remote=44.199.80.228:443
        at Object.connect (node:internal/tls/wrap:1895:13)
        at Object.connect (node:internal/http2/core:3694:22)
        at /data/node_modules/alexa-remote2/alexa-http2push.js:140:37
        at /data/node_modules/alexa-remote2/alexa-remote.js:561:21
  2026-10-01T01:45:22.719Z end TLSSocket remote=44.199.80.228:443
        at Object.connect (node:internal/tls/wrap:1895:13)
        at Object.connect (node:internal/http2/core:3694:22)
        at /data/node_modules/alexa-remote2/alexa-http2push.js:140:37
        at /data/node_modules/alexa-remote2/alexa-remote.js:561:21
  2026-10-01T01:45:22.721Z error TLSSocket remote=44.199.80.228:443
        at Object.connect (node:internal/tls/wrap:1895:13)
        at Object.connect (node:internal/http2/core:3694:22)
        at /data/node_modules/alexa-remote2/alexa-http2push.js:140:37
        at /data/node_modules/alexa-remote2/alexa-remote.js:561:21

gtalusan and others added 2 commits October 1, 2026 17:17
…-init

A re-init (initPushConnection) calls removeAllListeners() and disconnect()
on the old push instance while its token refresh request is still in
flight. When the token callback later resumes connect() and Amazon drops
the connection mid-TLS-handshake, the http2 session re-emits the socket
error on the session, which forwards it to this.emit('error') on the
push — and with no listeners left, EventEmitter throws and kills the
whole process.

Two changes:
- connect() bails out if the push was stopped while waiting for the
  token, so a disconnected push never opens a socket.
- All this.emit('error') sites are guarded by a listener count check,
  so a listener-less push can never throw an uncaught exception.

Co-Authored-By: Claude Code <noreply@anthropic.com>
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