-
-
Notifications
You must be signed in to change notification settings - Fork 754
Closed
Description
Please avoid duplicates
- I checked all open bugs and none of them matched my problem.
Reproducible test case
https://runkit.com/cspotcode/643ebe6ec050bf00085bd514
Nock Version
main branch
Node Version
v18.16.0
TypeScript Version
N/A
What happened?
Nock is incompatible with node 18.
Nock's Socket class does not pass node's internal isNodeStream check: https://github.com/nodejs/node/blob/43d167a262d0772a73ec1e21316e722bad71e4f8/lib/internal/streams/utils.js#L50-L60
When calling response.destroy(), node internally calls require('stream').finished(response.socket)
In some code paths, node uses isNodeStream to validate the socket, raising an error if it fails.
The error can be triggered by this code:
const http = require('http');
const nock = require('./'); // <-- I am reproducing in a clone of nock, the latest main branch
nock('http://example.test').get('/').reply(403)
http
.get('http://example.test/', res => {
res.destroy();
});Logging:
❯ node ./foo.js
node:events:491
throw er; // Unhandled 'error' event
^
TypeError [ERR_INVALID_ARG_TYPE]: The "stream" argument must be an instance of ReadableStream, WritableStream, or Stream. Received an instance of Socket
at new NodeError (node:internal/errors:399:5)
at eos (node:internal/streams/end-of-stream:69:11)
at IncomingMessage._destroy (node:_http_incoming:234:21)
at _destroy (node:internal/streams/destroy:109:10)
at IncomingMessage.destroy (node:internal/streams/destroy:71:5)
at OverriddenClientRequest.<anonymous> (/home/ubuntu/dev/nock/foo.js:6:13)
at Object.onceWrapper (node:events:628:26)
at OverriddenClientRequest.emit (node:events:513:28)
at Timeout.respond [as _onTimeout] (/home/ubuntu/dev/nock/lib/playback_interceptor.js:307:11)
at listOnTimeout (node:internal/timers:569:17)
Emitted 'error' event on IncomingMessage instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'ERR_INVALID_ARG_TYPE'
}
Would you be interested in contributing a fix?
- yes
Reactions are currently unavailable