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.

"getaddrinfo EAI_AGAIN" on CI

See original GitHub issue

Prerequisites

Environment check

  • I’m using the latest msw version
  • I’m using Node.js version 14 or higher

Node.js version

14.x / 16.x

Reproduction repository

https://github.com/benjdlambert/msw-example-repo

Reproduction steps

Unable to reproduce this locally, think some form of race condition but it happens in our CI which is github actions running ubuntu-latest, this has been known to pass using macos-latest.

https://github.com/benjdlambert/msw-example-repo/runs/6130933244?check_suite_focus=true

Is a failure run, notice the logs how the mock is not stable under run test .

Fetch 90 failed with FetchError: request to https://nono-nononono-nononono-nono-theres-no-host/ failed, reason: getaddrinfo EAI_AGAIN nono-nononono-nononono-nono-theres-no-host
        at NodeClientRequest.<anonymous> (/home/runner/work/msw-example-repo/msw-example-repo/node_modules/node-fetch/lib/index.js:[14](https://github.com/benjdlambert/msw-example-repo/runs/6130933244?check_suite_focus=true#step:6:14)91:11)
        at NodeClientRequest.emit (events.js:400:28)
        at NodeClientRequest.Object.<anonymous>.NodeClientRequest.emit (/home/runner/work/msw-example-repo/msw-example-repo/node_modules/@mswjs/interceptors/src/interceptors/ClientRequest/NodeClientRequest.ts:284:22)
        at TLSSocket.socketErrorListener (_http_client.js:475:9)
        at TLSSocket.emit (events.js:400:28)
        at emitErrorNT (internal/streams/destroy.js:106:8)
        at emitErrorCloseNT (internal/streams/destroy.js:74:3)
        at processTicksAndRejections (internal/process/task_queues.js:82:21)

      at test.test.ts:56:17

  console.log
    Fetch 98 failed with FetchError: request to https://nono-nononono-nononono-nono-theres-no-host/ failed, reason: getaddrinfo EAI_AGAIN nono-nononono-nononono-nono-theres-no-host
        at NodeClientRequest.<anonymous> (/home/runner/work/msw-example-repo/msw-example-repo/node_modules/node-fetch/lib/index.js:1491:11)
        at NodeClientRequest.emit (events.js:400:28)
        at NodeClientRequest.Object.<anonymous>.NodeClientRequest.emit (/home/runner/work/msw-example-repo/msw-example-repo/node_modules/@mswjs/interceptors/src/interceptors/ClientRequest/NodeClientRequest.ts:284:22)
        at TLSSocket.socketErrorListener (_http_client.js:475:9)
        at TLSSocket.emit (events.js:400:28)
        at emitErrorNT (internal/streams/destroy.js:106:8)
        at emitErrorCloseNT (internal/streams/destroy.js:74:3)
        at processTicksAndRejections (internal/process/task_queues.js:82:21)

      at test.test.ts:56:[17](https://github.com/benjdlambert/msw-example-repo/runs/6130933244?check_suite_focus=true#step:6:17)

Current behavior

We have recently upgraded from 0.35 to latest in this PR https://github.com/backstage/backstage/pull/10589 and noticed that theres some failures for some tests. Been digging in this for the last few days to work out what is going on and wether it’s something that we own that we could fix.

Looks like when setting up the mocks that the mock is not stable, and repeated requests to the mocked endpoint will sometimes yield the mocked data, and sometimes in our case it will try to make the request to the origin. Which for the purpose of the test case that I have reported is some unknown DNS and that’s the error we get.

As you can see in the simple reproduction example that I have provided, we setup a mock, and then in the test we repeatedly call that mocked endpoint and get some DNS resolution errors which happen sporadically throughout the test run. This is of course an extreme example hitting it many times, but it happens when it’s not called under load and causes flakey test failures.

Interestingly running the same tests under macos-latest as the agent in CI seemed to work. So not sure if some slowness or fastness is one of the runners is mitigating this, and maybe it’s a race condition.

Haven’t had much time to dig into the source code, but it looks like this could be something that’s been changed or added in the versions after 0.35 to now as our other test suite is stable.

Expected behavior

The fetch request returns the mock data all the time, rather than sometimes trying to bypass the mocked request and actually call out to the original origin.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
benjdlambertcommented, May 30, 2022

No probs at all! Please let us know if there’s anyway I can help out 🙏

0reactions
kettanaitocommented, May 30, 2022

Released: v0.42.0 🎉

This has been released in v0.42.0!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gitlab-runner: npm ci getaddrinfo EAI_AGAIN registry.npmjs.org
The EAI_AGAIN occurs when a getaddrinfo call (a DNS request to resolve a hostname to its IP) times out or is rejected by...
Read more >
What's the cause of the error 'getaddrinfo EAI_AGAIN'?
EAI_AGAIN is a DNS lookup timed out error, means it is a network connectivity error or proxy related error.
Read more >
I am facing EAI_AGAIN errors when pushing or running unit ...
I was facing getaddrinfo eai_again error and tried adding 3 minute, 6 minute, 9 minute etc delay for each parallel build so that...
Read more >
[Solved]-Express js npm install fails reason - appsloveworld.com
[Solved]-Express js npm install fails reason: getaddrinfo EAI_AGAIN-docker ... This problem disappeared after two days (same network, same computer etc.) It is ...
Read more >
EAI_AGAIN errors when pushing or running unit tests in a ...
We are running Jenkins Pipeline CI on AWS. Some Googling suggests this EAI_AGAIN error (coming from Node.js that sfdx runs on) means: Temporary ......
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