()
| 29 | ): void { |
| 30 | let fired = false; |
| 31 | const fire = (): void => { |
| 32 | if (fired) return; |
| 33 | fired = true; |
| 34 | // Drop the fd from epoll so a hung/half-closed socket can't keep waking |
| 35 | // the loop. Best-effort: the stream may already be torn down. |
| 36 | try { |
| 37 | (stream as Partial<{ destroy(): void }>).destroy?.(); |
| 38 | } catch { |
| 39 | /* already gone */ |
| 40 | } |
| 41 | onTerminal(); |
| 42 | }; |
| 43 | stream.on('end', fire); |
| 44 | stream.on('close', fire); |
| 45 | stream.on('error', fire); |