Commit 5783375
fix(websocket): time out a stalled connect/auth handshake so retry can fire
If the server accepts the TCP connection but never completes the
application-layer handshake -- it never returns the WebSocket 101 upgrade,
or upgrades but never sends auth_ok -- none of the socket's
open/message/close/error events fire. connect() therefore never settles the
connection promise and never schedules its onClose retry, so the node sits
at "connecting" indefinitely (21 hours in the reported case) until Node-RED
is restarted. This happens when the HA host's kernel is alive (answers ARP,
completes TCP handshakes) but the HA process is blocked, e.g. a storage
stall / uninterruptible I/O wait.
Add two timeouts, both routed into the existing onClose retry path:
- handshakeTimeout on the ws socket: ws emits 'error' if the opening HTTP
handshake (the 101 upgrade) does not complete in time. Covers the
never-upgrades case (the deterministic bare-TCP-listener repro).
- an overall auth deadline: terminate() the socket if auth_ok has not
arrived. Covers upgrade-but-never-authenticates. terminate() (not
close()) forces a prompt 'close' even on a wedged half-open socket whose
peer will never complete a closing handshake.
The timer is cleared on auth_ok and on close. Healthy connections are
unaffected. No public API change.
Co-authored-by: jschwalbe <jschwalbe@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>1 parent 868d9e7 commit 5783375
1 file changed
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
16 | 27 | | |
17 | 28 | | |
18 | 29 | | |
| |||
49 | 60 | | |
50 | 61 | | |
51 | 62 | | |
| 63 | + | |
52 | 64 | | |
53 | 65 | | |
54 | 66 | | |
55 | 67 | | |
56 | 68 | | |
57 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
58 | 90 | | |
59 | 91 | | |
60 | 92 | | |
| |||
78 | 110 | | |
79 | 111 | | |
80 | 112 | | |
| 113 | + | |
81 | 114 | | |
82 | 115 | | |
83 | 116 | | |
| |||
104 | 137 | | |
105 | 138 | | |
106 | 139 | | |
| 140 | + | |
107 | 141 | | |
108 | 142 | | |
109 | 143 | | |
| |||
0 commit comments