keep-alive matching not returning
Author: stephen-willoughbyCreated Oct 13, 2025Updated Jul 24, 2026
Labelsbuginterceptors
Please avoid duplicates
- I checked all open bugs and none of them matched my problem.
Reproducible test case
https://github.com/stephen-willoughby/nock-keep-alive-issue/blob/main/index.js
Nock Version
Node Version
v22.14.0
TypeScript Version
No response
What happened?
This code works with [email protected], but not [email protected].
See output
Setting up nock interceptor for https://localhost:1234
Pending mocks before: [ 'GET https://localhost:1234/' ]
Making request...
Creating request promise...
Creating timeout promise...
Racing promises...
Nock intercepted a request: /
Request headers: {"accept-encoding":"gzip, deflate, br","connection":"keep-alive","host":"localhost:1234","user-agent":"got (https://github.com/sindresorhus/got)"}
Timeout reached, aborting request...
Error making request: Error Request timed out after 1 second
Pending mocks: []
Is nock active? true
Request completed or failedSetting up nock interceptor for https://localhost:1234
Pending mocks before: [ 'GET https://localhost:1234/' ]
Making request...
Creating request promise...
Creating timeout promise...
Racing promises...
Nock intercepted a request: /
Request headers: {"user-agent":"got (https://github.com/sindresorhus/got)","connection":"keep-alive","accept-encoding":"gzip, deflate, br","host":"localhost:1234"}
Request completed successfully
Success! Nock intercepted the request.
Response status: 200
Response body: {"message":"Hello from nock interceptor!"}
Pending mocks: []
Is nock active? true
Request completed or failedSee how 14 times out, it has matched but never returns. With 13 it simply works and got gets the nocked response. Any other header, e.g. 'abc:123' works
Would you be interested in contributing a fix?
- yes
Source: nock/nock