Skip to content

Nock recorder + Got + CookieJar + Set-Cookie causes Node to exit #2086

@davispuh

Description

@davispuh

What is the expected behavior?

Node not to exit.
Even if this is a bug in Node itself then there should be some workaround.

What is the actual behavior?

Node exits with status code 13

How to reproduce the issue

Rack server

run Proc.new { |env| [200, [["Set-Cookie", "cookie=test"]], ["response"]] }

Smallest test case I got so far

import Nock from "nock";
import Got from "got";
import ToughCookie from "tough-cookie";

// Commenting this out it works
Nock.recorder.rec({dont_print: true});

console.log("Before request");

await Got("http://localhost:9292/", { cookieJar: new ToughCookie.CookieJar() });

console.log("We never get here :(");

Debug output

nock.back New nock back mode: dryrun +0ms
nock.recorder 0 restoring all the overridden http/https properties +0ms
nock.common restoring requests +0ms
nock.intercept restoring overridden ClientRequest +0ms
nock.intercept - ClientRequest was not overridden +0ms
nock.intercept Overriding ClientRequest +0ms
nock.intercept ClientRequest overridden +0ms
nock.common overriding requests +0ms
nock.common - overriding request for http +0ms
nock.common - overridden request for http +0ms
nock.common - overriding request for https +0ms
nock.common - overridden request for https +0ms
nock.recorder start recording 1 {
dont_print: true,
enable_reqheaders_recording: false,
logging: [Function: log],
output_objects: false,
use_separator: true
} +40ms
nock.recorder 1 restoring overridden requests before new overrides +2ms
nock.common restoring requests +41ms
nock.common - restoring request for http +0ms
nock.common - restored request for http +0ms
nock.common - restoring request for https +0ms
nock.common - restored request for https +0ms
nock.intercept restoring overridden ClientRequest +41ms
nock.intercept - ClientRequest restored +0ms
nock.common overriding requests +0ms
nock.common - overriding request for http +0ms
nock.common - overridden request for http +0ms
nock.common - overriding request for https +0ms
nock.common - overridden request for https +0ms
Before request
nock.recorder req.end +37ms
nock.recorder 1 intercepting http request to record +5ms
nock.recorder finished setting up intercepting +0ms
nock.recorder 1 http intercepted request ended +2ms
nock.common options.hostname in the end: "localhost" +45ms
nock.common options.host in the end: "localhost:9292" +0ms
nock.recorder out:
nock('http://localhost:9292', {"encodedQueryParams":true})
.get('/')
.reply(200, "response", [
'Set-Cookie',
'cookie=test',
'Connection',
'close',
'Content-Length',
'8'
]); +1ms

Notice how there's no last console output and

$ echo $status
13

If I comment out Nock.recorder.rec then it works.
Output

nock.back New nock back mode: dryrun +0ms
nock.recorder 0 restoring all the overridden http/https properties +0ms
nock.common restoring requests +0ms
nock.intercept restoring overridden ClientRequest +0ms
nock.intercept - ClientRequest was not overridden +0ms
nock.intercept Overriding ClientRequest +0ms
nock.intercept ClientRequest overridden +0ms
nock.common overriding requests +0ms
nock.common - overriding request for http +0ms
nock.common - overridden request for http +0ms
nock.common - overriding request for https +0ms
nock.common - overridden request for https +0ms
Before request
nock.common options.hostname in the end: "localhost" +71ms
nock.common options.host in the end: "localhost:9292" +0ms
nock.intercept interceptors for "localhost:9292" +71ms
nock.intercept filtering interceptors for basepath http://localhost:9292 +0ms
nock.common options.host: localhost:9292 +0ms
nock.common options.hostname in the end: "localhost" +0ms
nock.common options.host in the end: "localhost:9292" +0ms
nock.intercept Net connect  enabled for localhost:9292 +0ms
We never get here :(

Also if I change server's cookie header to different (eg. wrong Set-Cookies) then it also works

nock.back New nock back mode: dryrun +0ms
nock.recorder 0 restoring all the overridden http/https properties +0ms
nock.common restoring requests +0ms
nock.intercept restoring overridden ClientRequest +0ms
nock.intercept - ClientRequest was not overridden +0ms
nock.intercept Overriding ClientRequest +0ms
nock.intercept ClientRequest overridden +0ms
nock.common overriding requests +0ms
nock.common - overriding request for http +0ms
nock.common - overridden request for http +0ms
nock.common - overriding request for https +0ms
nock.common - overridden request for https +0ms
nock.recorder start recording 1 {
dont_print: true,
enable_reqheaders_recording: false,
logging: [Function: log],
output_objects: false,
use_separator: true
} +39ms
nock.recorder 1 restoring overridden requests before new overrides +1ms
nock.common restoring requests +39ms
nock.common - restoring request for http +0ms
nock.common - restored request for http +0ms
nock.common - restoring request for https +0ms
nock.common - restored request for https +1ms
nock.intercept restoring overridden ClientRequest +40ms
nock.intercept - ClientRequest restored +0ms
nock.common overriding requests +0ms
nock.common - overriding request for http +0ms
nock.common - overridden request for http +0ms
nock.common - overriding request for https +0ms
nock.common - overridden request for https +0ms
Before request
nock.recorder req.end +38ms
nock.recorder 1 intercepting http request to record +5ms
nock.recorder finished setting up intercepting +0ms
nock.recorder 1 http intercepted request ended +3ms
nock.common options.hostname in the end: "localhost" +45ms
nock.common options.host in the end: "localhost:9292" +0ms
nock.recorder out:
nock('http://localhost:9292', {"encodedQueryParams":true})
.get('/')
.reply(200, "response", [
'Set-Cookies',
'cookie=test',
'Connection',
'close',
'Content-Length',
'8'
]); +1ms
We never get here :(

Does the bug have a test case?

Yes, see above

Versions

Software Version(s)
Nock v13.0.4 and git master
Node v14.10.1
TypeScript 4.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions