testcafe: Sockets hanging with node16

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 25 (2 by maintainers)

Commits related to this issue

Most upvoted comments

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

Hello, this problem still persists in Firefox and Safari. I am using tetscafe version 3.2.0 and node 18.17.1. Do you plan to fix that for Firefox and Safari?

Hello @dcsaszar ,

Thank you for pointing out the issue to us. According to your description, the cause of the problem most likely is different from the original issue in this thread, although the symptoms are the same. Could you please create a separate issue with a project sample that we can use to reproduce the problem? It will help us to improve the Proxyless mode and take it out of the experimental state.

Hi @andrzej-kodify

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