|
| 1 | +/* eslint-disable no-console */ |
1 | 2 | import * as crypto from 'crypto'; |
2 | 3 | import type { SrvRecord } from 'dns'; |
3 | 4 | import { type EventEmitter } from 'events'; |
@@ -1571,7 +1572,37 @@ export function addAbortSignalToStream( |
1571 | 1572 |
|
1572 | 1573 | const abortListener = addAbortListener(signal, function () { |
1573 | 1574 | stream.off('close', abortListener[kDispose]).off('error', abortListener[kDispose]); |
1574 | | - stream.destroy(this.reason); |
| 1575 | + const removeAll = stream.removeAllListeners.bind(stream); |
| 1576 | + |
| 1577 | + //@ts-expect-error: overwrite |
| 1578 | + stream.removeAllListeners = function (...args) { |
| 1579 | + const removingError = args.length === 0 || args.includes('error'); |
| 1580 | + if (removingError) { |
| 1581 | + console.log('removing all', args, new Error('why are u removing my error listener')); |
| 1582 | + } |
| 1583 | + return removeAll(...args); |
| 1584 | + }; |
| 1585 | + |
| 1586 | + stream.on('removeListener', (name, listener) => { |
| 1587 | + if (name === 'error') { |
| 1588 | + console.log( |
| 1589 | + 'who doth remove my error listener', |
| 1590 | + new Error('error listener gone missing!!'), |
| 1591 | + listener |
| 1592 | + ); |
| 1593 | + } |
| 1594 | + }); |
| 1595 | + |
| 1596 | + const error = new Error( |
| 1597 | + //@ts-expect-error: we added these |
| 1598 | + `sad: ${stream.___socketId}: error listeners: ${stream.listenerCount('error')} + ${stream.___stack}`, |
| 1599 | + { cause: this.reason } |
| 1600 | + ); |
| 1601 | + |
| 1602 | + //@ts-expect-error: adding this for debug |
| 1603 | + error.stream = stream; |
| 1604 | + |
| 1605 | + stream.destroy(error); |
1575 | 1606 | }); |
1576 | 1607 | // not nearly as complex as node's eos() but... do we need all that?? sobbing emoji. |
1577 | 1608 | stream.once('close', abortListener[kDispose]).once('error', abortListener[kDispose]); |
|
0 commit comments