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.

Sockets hanging with node16

See original GitHub issue

What is your Scenario?

Web app that makes client side fetch to two API endpoints, both on localhost but one is not running, so doesn’t accept connections (which is fine, error is handled and app is functional)

Running tests with node v14.x is just fine, after switching to v16 tests start to break after a while Symptoms observed in chrome network tools are that calls to both API endpoints are in pending state

After a while of debugging I’ve noticed that testcafe’s behaviour for requests that are supposed to fail (since there’s no server listening) is much different in node16 than node14 Looking at network tools: Node v16 image

Node v14 image

As you can see, in node 14 such request fails instantly, as it should. With node 16 the request is pending. I cannot prepare a sample that reproduces my exact problem (where after a while both /api calls are constantly pending in subsequent tests) but I’m assuming maybe sockets are not properly closed in my case and just saturate some system limits

What is the Current behavior?

Fetch requests that are supposed to fail are pending

What is the Expected behavior?

Requests should fail immediately if there’s no server listening on the other end

What is your public website URL? (or attach your complete example)

https://github.com/andrzej-kodify/testcafe-hanging-sockets Launch server

npm run serve

Launch tests with node 16

npm run test:debug

and look in chrome network tools on how failed requests behave. Tests are passing, no JS errors.

Do the same with node 14 - requests fail immediately, and there’s a JS error (as fetch exception is not handled)

What is your TestCafe test code?

// https://github.com/andrzej-kodify/testcafe-hanging-sockets

const { Selector } = require("testcafe");

fixture('Fixture');

for (let i=0; i<1000; i++) {
    test(`Test ${i}`, async (browser) => {
        await browser.navigateTo('http://localhost:3666/');
        await browser.expect(Selector('#response').innerText).match(/[0-9]+/);
    });
}

Your complete configuration file

No response

Your complete test report

No response

Screenshots

No response

Steps to Reproduce

TestCafe version

1.19.0

Node.js version

version v14.18.1 runs fine, versions 16+ (e.g. v16.15.1) fail

Command-line arguments

chrome

Browser name(s) and version(s)

Version 102.0.5005.61 (Official Build) (arm64)

Platform(s) and version(s)

macOS 12.4

Other

I’ve made silly workaround by applying this patch in my actual tests https://github.com/andrzej-kodify/testcafe-hanging-sockets/blob/main/testcafe-hammerhead%2B24.5.16.patch

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

4reactions
VasilyStrelyaevcommented, Oct 10, 2022

Thank you for the additional information! We increased the frequency level for this issue, which will give it higher priority during our future planning.

1reaction
miherlosevcommented, Jun 21, 2022

Hi @andrzej-kodify

Thank you for the shared example. I’ve reproduced the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJS - What does "socket hang up" actually mean?
There are two cases when socket hang up gets thrown: When you are a client. When you, as a client, send a request...
Read more >
15 Common Error Codes in Node.js and How to Fix Them
15 Common Error Codes in Node.js and How to Fix Them · Error: socket hang up at connResetException (node:internal/errors:691:14) at Socket.
Read more >
HTTP | Node.js v19.3.0 Documentation
Sockets are removed from an agent when the socket emits either a 'close' event or an 'agentRemove' event. When intending to keep one...
Read more >
npm i socket timeout | The Search Engine You Control
npm info retry will retry, error on last attempt: Error: socket hang up ... dockerfile FROM node:16-alpine3.15 # Copy the current directory into...
Read more >
Homebridge Log Bombarded With "Socket Hang Up" - Reddit
Failed to check registry.npmjs.org for updates: "socket hang up" ... I would follow these steps here to properly update to node 16, ...
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