question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mastermattcommented, Mar 1, 2021

This issue arose again today for me.

I’m going to create a PR to remove the resume() and we’ll see what it looks like.

ping @koerbcm

0reactions
github-actions[bot]commented, Mar 2, 2021

🎉 This issue has been resolved in version 13.0.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop Results From Across the Web

A brand new website interface for an even better experience!
Nock recorder + Got + CookieJar + Set-Cookie causes Node to exit.
Read more >
Requests setting cookies in cookieJar including subdomains
I think it has something to do with the URL passed into setCookie . I've attempted to change that to different variations to...
Read more >
Untitled
Lajme shqip live rtk, Sfgui static, The loser in the end queen mp3, Drosophila buzzatii ... Kucukkoy endustri meslek lisesi, Canopen node id,...
Read more >
npm - Snyk
... @babel/node · @babel/parser · @babel/plugin-proposal-class-properties · @babel/plugin-proposal-decorators · @babel/plugin-proposal-export-default-from ...
Read more >
Nock: HTTP Mocking and Expectations - Morioh
Nock. HTTP server mocking and expectations library for Node.js ... GET /my/url => goes through nock // GET /other/url => actually makes request...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found