Commit 6505ed2
committed
Guard against null socket in nextWrite
When a connection closes, `closed()` sets `socket = null` (after rejecting
any in-flight query with CONNECTION_CLOSED). A write smaller than 1024 bytes
schedules `setImmediate(nextWrite)`; if the connection closes before that
callback runs, `nextWrite` dereferences a null socket and throws an
uncatchable `TypeError: Cannot read properties of null (reading 'write')`,
crashing the process.
Add an early return when the socket is already gone. At that point the
query has already been rejected through the normal close path, so the
buffered write is moot — skipping it is safe and simply avoids the crash.
Fixes #1066, #11541 parent e7dfa14 commit 6505ed2
4 files changed
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
| 257 | + | |
| 258 | + | |
257 | 259 | | |
258 | 260 | | |
259 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
| 258 | + | |
| 259 | + | |
258 | 260 | | |
259 | 261 | | |
260 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
| |||
0 commit comments