| 53 | |
| 54 | |
| 55 | _destroy(err, callback) { |
| 56 | const otherSide = this.#otherSide; |
| 57 | |
| 58 | if (otherSide !== null && !otherSide.destroyed) { |
| 59 | // Use nextTick to avoid crashing the current execution stack (like HTTP parser) |
| 60 | process.nextTick(() => { |
| 61 | if (otherSide.destroyed) return; |
| 62 | |
| 63 | if (err) { |
| 64 | // Destroy the other side, without passing the 'err' object. |
| 65 | // This closes the other side gracefully so it doesn't hang, |
| 66 | // but prevents the "Unhandled error" crash. |
| 67 | otherSide.destroy(); |
| 68 | } else { |
| 69 | // Standard graceful close |
| 70 | otherSide.push(null); |
| 71 | } |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | callback(err); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | function duplexPair(options) { |