vlucas / frisby

Frisby is a REST API testing framework built on Jest that makes testing API endpoints easy, fast, and fun.

Home Page:http://frisbyjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Socket hang up / ECONNRESET errors with Node.js 20.x

bkimminich opened this issue · comments

With Node.js 20.x previously working and otherwise unchanged Frisby tests start failing with either

Summary of all failing tests
...
    FetchError: request to http://localhost:3000/rest/user/login failed, reason: socket hang up

      at ClientRequest.<anonymous> (node_modules/node-fetch/lib/index.js:1501:11)

(Example: https://github.com/juice-shop/juice-shop/actions/runs/6539449747/job/17758607028#step:6:387)
or

Summary of all failing tests
...
    FetchError: request to http://localhost:3000/rest/user/login failed, reason: read ECONNRESET

      at ClientRequest.<anonymous> (node_modules/node-fetch/lib/index.js:1501:11)

(Example: https://github.com/juice-shop/juice-shop/actions/runs/6539449747/job/17758607313#step:6:579)
errors.

This is very likely related to changes in node-fetch and/or Node.js internal connection handling. This behavior is fully reproducible and deterministic. It is not limited to specific test cases, as disabling or removing the failing test will simply make another test fail from the same error. This can be repeated until no more tests are left... (which solves the problem, but not in a good way... 🤣)

For reproduction steps of the above failing suites, please see juice-shop/juice-shop#2068.

Likely related issues we identified are

❓Can other Frisby.js users confirm the behavior? If Node.js 20.x works fine for you, could you please provide a link to your working Frisby.js setup with Node.js 20.x?

I guess this relates to node-fetch/node-fetch#1765 which is fixed in node-fetch@2.6.13.

Are you using frisby@2.1.3? Although this issue should be fixed by #597, frisby actually has not been released for a long time. Please follow #593. Otherwise, please use the commit hash of the latest master instead.

Just updating node-fetch does not remediate the issue, at least it didn't for me. Only closing the connection did fix it permanently. And funny enough it wasn't enough to add the header via the global setup configuration. Not sure if there's some timing/race condition happening, but the the only stable test executions I was able to get, was from my fork... 🤷‍♂️