* @param {import ('stream').Stream} stream * @param {Error} [err] * @returns {void}
(stream, err)
| 360 | * @returns {void} |
| 361 | */ |
| 362 | function destroy (stream, err) { |
| 363 | if (stream == null || !isStream(stream) || isDestroyed(stream)) { |
| 364 | return |
| 365 | } |
| 366 | |
| 367 | if (typeof stream.destroy === 'function') { |
| 368 | if (Object.getPrototypeOf(stream).constructor === IncomingMessage) { |
| 369 | // See: https://github.com/nodejs/node/pull/38505/files |
| 370 | stream.socket = null |
| 371 | } |
| 372 | |
| 373 | stream.destroy(err) |
| 374 | } else if (err) { |
| 375 | queueMicrotask(() => { |
| 376 | stream.emit('error', err) |
| 377 | }) |
| 378 | } |
| 379 | |
| 380 | if (stream.destroyed !== true) { |
| 381 | stream[kDestroyed] = true |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | const KEEPALIVE_TIMEOUT_EXPR = /timeout=(\d+)/ |
| 386 | /** |
no test coverage detected