Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karma + Node.js 17: can't connect to karma server. There is no server listening on port 9876 #3730

Closed
marcoscaceres opened this issue Nov 23, 2021 · 14 comments · Fixed by #3792 or karronoli/redpen#10 · May be fixed by akjk-org/sphinx#2, vinit-aikido/terragoat#42 or kobaska/ng-memory-leak#16
Labels

Comments

@marcoscaceres
Copy link

When running under Node 17, running karma reports:

 can't connect to karma server. There is no server listening on port 9876 

Switching back to Node 16 seems to "fix" the issue.

See also:
https://youtrack.jetbrains.com/issue/WEB-53632

@marcoscaceres
Copy link
Author

In case it helps, here are some dependencies (in case it's one of those that is causing it):

    "karma": "^6.3.9",
    "karma-chrome-launcher": "^3.1.0",
    "karma-firefox-launcher": "^2.1.2",
    "karma-jasmine": "^4.0.1",
    "karma-jasmine-html-reporter": "^1.7.0",
    "karma-mocha-reporter": "^2.2.5",
    "karma-safari-launcher": "^1.0.0",

@marcoscaceres
Copy link
Author

marcoscaceres commented Nov 23, 2021

Some steps to reproduce.

  1. nvm install 17; nvm use 17;
  2. git clone git@github.com:w3c/respec.git
  3. npm i
  4. npm start -- --browser Chrome --grep "W3C"

Console should show the error above: "can't connect to karma server. There is no server listening on port 9876".

To confirm.. you can switch back to Node 16 and it should work fine again.

@devoto13
Copy link
Collaborator

I've tried the above steps using Node v17.1.0, Chrome 96.0.4664.55 on macOS 12.0.1 and the tests ran successfully. I've also tried our own test suite which also completed successfully. I've tried to run using Karma configuration from WebStorm and it worked as well. Can you double check on your side?

devoto13 added a commit to devoto13/karma that referenced this issue Nov 23, 2021
Update documentation, so that it does not become outdated whenever a new version of Node is released.

Test on the current version of Node, so we can spot problems early, but don't claim to support it as current release line often introduces bugs, which are later fixed by Node itself.

Fixes karma-runner#3730, fixes karma-runner#3728
Closes karma-runner#3729
@devoto13
Copy link
Collaborator

Reproduced on CI: https://github.com/karma-runner/karma/runs/4304771965?check_suite_focus=true. I'll look more into it tomorrow.

@marcoscaceres
Copy link
Author

Thanks! and yeah, we were able to reproduce it on a different Mac (cc @sideshowbarker) running different versions of MacOS (Monterey and Big Sur)... so, at least, it doesn't seem to be an OS thing, but more likely a Node 17 thing.

@ChaitanyaBabar
Copy link

+1

@eweitz
Copy link

eweitz commented May 9, 2022

This issue also occurs with Node 18, unfortunately.

devoto13 added a commit to devoto13/karma that referenced this issue May 10, 2022
Update documentation, so that it does not become outdated whenever a new version of Node is released.

Test on the current version of Node, so we can spot problems early, but don't claim to support it as current release line often introduces bugs, which are later fixed by Node itself.

Fixes karma-runner#3730, fixes karma-runner#3728
Closes karma-runner#3729
@devoto13
Copy link
Collaborator

devoto13 commented May 10, 2022

nodejs/node#40702 seems to be the culprit. Node 17 changed the DNS resolution, so now it resolves localhost according to the OS settings instead of IPv4 first. The Karma server only listens on IPv4 address (0.0.0.0) by default, but the requests are sent to localhost and localhost is resolved into IPv6 address (::) in Node 17+. So the run request is unable to reach the Karma server.

I'll think what's the best way to make it work out of the box. In the meantime you can address the issue by setting listenAddress to :: either in config or using LISTEN_ADDR environment variable.

devoto13 added a commit to devoto13/karma that referenced this issue May 10, 2022
Node 17+ changed the DNS resolution (see nodejs/node#40702), so now it resolves `localhost` according to the OS settings instead of IPv4-address first. The Karma server only listens on IPv4 address (127.0.0.1) by default, but the requests are sent to `localhost` in several places and `localhost` is resolved into IPv6 address (`::`) in Node 17+. So the run/stop/proxy request is unable to reach the Karma server and produces an error. This commit configures karma to use the IPv4-address first approach in newer Node version as well.

In the future major release, we may consider changing defaults to listen on IPv6 address instead, but IPv6 is not supported in Docker on macOS and Windows, so I think we should not rush such a change to make sure karma works there out of the box.

Fixes karma-runner#3730
devoto13 added a commit to devoto13/karma that referenced this issue May 10, 2022
Node 17+ changed the DNS resolution (see nodejs/node#40702), so now it resolves `localhost` according to the OS settings instead of IPv4-address first. The Karma server only listens on IPv4 address (127.0.0.1) by default, but the requests are sent to `localhost` in several places and `localhost` is resolved into IPv6 address (`::`) in Node 17+. So the run/stop/proxy request is unable to reach the Karma server and produces an error. This commit configures karma to use the IPv4-address first approach in newer Node version as well.

In the future major release, we may consider changing defaults to listen on IPv6 address instead, but IPv6 is not supported in Docker on macOS and Windows, so I think we should not rush such a change to make sure karma works there out of the box.

Fixes karma-runner#3730
devoto13 added a commit to devoto13/karma that referenced this issue May 10, 2022
Node 17+ changed the DNS resolution (see nodejs/node#40702), so now it resolves `localhost` according to the OS settings instead of IPv4-address first. The Karma server only listens on IPv4 address (127.0.0.1) by default, but the requests are sent to `localhost` in several places and `localhost` is resolved into IPv6 address (`::`) in Node 17+. So the run/stop/proxy request is unable to reach the Karma server and produces an error. This commit configures karma to use the IPv4-address first approach in newer Node version as well.

In the future major release, we may consider changing defaults to listen on IPv6 address instead, but IPv6 is not supported in Docker on macOS and Windows, so I think we should not rush such a change to make sure karma works there out of the box.

Fixes karma-runner#3730
devoto13 added a commit to devoto13/karma that referenced this issue May 11, 2022
Node 17+ changed the DNS resolution (see nodejs/node#40702), so now it resolves `localhost` according to the OS settings instead of IPv4-address first. The Karma server only listens on IPv4 address (127.0.0.1) by default, but the requests are sent to `localhost` in several places and `localhost` is resolved into IPv6 address (`::`) in Node 17+. So the run/stop/proxy request is unable to reach the Karma server and produces an error. This commit configures karma to use the IPv4-address first approach in newer Node version as well.

In the future major release, we may consider changing defaults to listen on IPv6 address instead, but IPv6 is not supported in Docker on macOS and Windows, so I think we should not rush such a change to make sure karma works there out of the box.

Fixes karma-runner#3730
jginsburgn pushed a commit that referenced this issue May 13, 2022
Node 17+ changed the DNS resolution (see nodejs/node#40702), so now it resolves `localhost` according to the OS settings instead of IPv4-address first. The Karma server only listens on IPv4 address (127.0.0.1) by default, but the requests are sent to `localhost` in several places and `localhost` is resolved into IPv6 address (`::`) in Node 17+. So the run/stop/proxy request is unable to reach the Karma server and produces an error. This commit configures karma to use the IPv4-address first approach in newer Node version as well.

In the future major release, we may consider changing defaults to listen on IPv6 address instead, but IPv6 is not supported in Docker on macOS and Windows, so I think we should not rush such a change to make sure karma works there out of the box.

Fixes #3730
karmarunnerbot pushed a commit that referenced this issue May 13, 2022
## [6.3.20](v6.3.19...v6.3.20) (2022-05-13)

### Bug Fixes

* prefer IPv4 addresses when resolving domains ([e17698f](e17698f)), closes [#3730](#3730)
@karmarunnerbot
Copy link
Member

🎉 This issue has been resolved in version 6.3.20 🎉

The release is available on:

Your semantic-release bot 📦🚀

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this issue May 13, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [karma](https://karma-runner.github.io/) ([source](https://github.com/karma-runner/karma)) | devDependencies | patch | [`6.3.19` -> `6.3.20`](https://renovatebot.com/diffs/npm/karma/6.3.19/6.3.20) |

---

### Release Notes

<details>
<summary>karma-runner/karma</summary>

### [`v6.3.20`](https://github.com/karma-runner/karma/blob/HEAD/CHANGELOG.md#&#8203;6320-httpsgithubcomkarma-runnerkarmacomparev6319v6320-2022-05-13)

[Compare Source](karma-runner/karma@v6.3.19...v6.3.20)

##### Bug Fixes

-   prefer IPv4 addresses when resolving domains ([e17698f](karma-runner/karma@e17698f)), closes [#&#8203;3730](karma-runner/karma#3730)

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1351
Reviewed-by: crapStone <crapstone@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@treysis
Copy link

treysis commented May 17, 2022

Why not make listening on :: the default instead of forcing IPv4?

@devoto13
Copy link
Collaborator

Because some environments may not support IPv6, that would be a breaking change for them. Primarily thinking about Docker on Windows/Mac here, but there could be others. I've added an item #3503 to consider this for the next major release.

@cherniavskii
Copy link

Hey @devoto13
Did you consider omitting host parameter in server.listen()?
According to the docs, IPv6/IPv4 are handled automatically:

If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise.
Source: https://nodejs.org/docs/latest-v16.x/api/net.html#serverlistenport-host-backlog-callback

Context: I've found this thread while investigating why karma server doesn't start on my setup (macOS 12.4, node v16.15.0) with default listenAddress.
I'm setting listenAddress to :: or localhost for now as a workaround, but I wonder if the suggestion above would solve the issue once and for all?

@devoto13
Copy link
Collaborator

devoto13 commented Jun 2, 2022

@cherniavskii That's actually a very good suggestion! I didn't know about this possibility. I think it would be indeed a good idea to do that in the next major instead of setting the default outright to IPv6.

I'm not sure if this is actually a root cause of the issue you describe. I would be interested to look into a minimal reproduction of the problem, because the defaults should work just fine on macOS 12.4 and Node v16.15.0. I have tested on my machine and I don't seem to experience any problems. Are you sure, you're running the latest version of karma?

@cherniavskii
Copy link

Hey @devoto13
Thanks for looking into this.

Indeed, I just realised that the root cause of the issue is that I use VPN (NordVPN to be specific).
Without it, the server starts just fine, so I guess VPN is messing with my network configuration.

Anyway, I've changed karma net-utils.js code locally to omit host - and it works both with VPN and without it.
For now I can use listenAddress: 'localhost' as a workaround.

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this issue Jun 17, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [karma](https://karma-runner.github.io/) ([source](https://github.com/karma-runner/karma)) | devDependencies | minor | [`6.3.20` -> `6.4.0`](https://renovatebot.com/diffs/npm/karma/6.3.20/6.4.0) |

---

### Release Notes

<details>
<summary>karma-runner/karma</summary>

### [`v6.4.0`](https://github.com/karma-runner/karma/blob/HEAD/CHANGELOG.md#&#8203;640-httpsgithubcomkarma-runnerkarmacomparev6320v640-2022-06-14)

[Compare Source](karma-runner/karma@v6.3.20...v6.4.0)

##### Features

-   support SRI verification of link tags ([dc51a2e](karma-runner/karma@dc51a2e))
-   support SRI verification of script tags ([6a54b1c](karma-runner/karma@6a54b1c))

#### [6.3.20](karma-runner/karma@v6.3.19...v6.3.20) (2022-05-13)

##### Bug Fixes

-   prefer IPv4 addresses when resolving domains ([e17698f](karma-runner/karma@e17698f)), closes [#&#8203;3730](karma-runner/karma#3730)

#### [6.3.19](karma-runner/karma@v6.3.18...v6.3.19) (2022-04-19)

##### Bug Fixes

-   **client:** error out when opening a new tab fails ([099b85e](karma-runner/karma@099b85e))

#### [6.3.18](karma-runner/karma@v6.3.17...v6.3.18) (2022-04-13)

##### Bug Fixes

-   **deps:** upgrade socket.io to v4.4.1 ([52a30bb](karma-runner/karma@52a30bb))

#### [6.3.17](karma-runner/karma@v6.3.16...v6.3.17) (2022-02-28)

##### Bug Fixes

-   **deps:** update colors to maintained version ([#&#8203;3763](karma-runner/karma#3763)) ([fca1884](karma-runner/karma@fca1884))

#### [6.3.16](karma-runner/karma@v6.3.15...v6.3.16) (2022-02-10)

##### Bug Fixes

-   **security:** mitigate the "Open Redirect Vulnerability" ([ff7edbb](karma-runner/karma@ff7edbb))

#### [6.3.15](karma-runner/karma@v6.3.14...v6.3.15) (2022-02-05)

##### Bug Fixes

-   **helper:** make mkdirIfNotExists helper resilient to concurrent calls ([d9dade2](karma-runner/karma@d9dade2)), closes [/github.com/karma-runner/karma-coverage/issues/434#issuecomment-1017939333](https://github.com//github.com/karma-runner/karma-coverage/issues/434/issues/issuecomment-1017939333)

#### [6.3.14](karma-runner/karma@v6.3.13...v6.3.14) (2022-02-05)

##### Bug Fixes

-   remove string template from client code ([91d5acd](karma-runner/karma@91d5acd))
-   warn when `singleRun` and `autoWatch` are `false` ([69cfc76](karma-runner/karma@69cfc76))
-   **security:** remove XSS vulnerability in `returnUrl` query param ([839578c](karma-runner/karma@839578c))

#### [6.3.13](karma-runner/karma@v6.3.12...v6.3.13) (2022-01-31)

##### Bug Fixes

-   **deps:** bump log4js to resolve security issue ([5bf2df3](karma-runner/karma@5bf2df3)), closes [#&#8203;3751](karma-runner/karma#3751)

#### [6.3.12](karma-runner/karma@v6.3.11...v6.3.12) (2022-01-24)

##### Bug Fixes

-   remove depreciation warning from log4js ([41bed33](karma-runner/karma@41bed33))

#### [6.3.11](karma-runner/karma@v6.3.10...v6.3.11) (2022-01-13)

##### Bug Fixes

-   **deps:** pin colors package to 1.4.0 due to security vulnerability ([a5219c5](karma-runner/karma@a5219c5))

#### [6.3.10](karma-runner/karma@v6.3.9...v6.3.10) (2022-01-08)

##### Bug Fixes

-   **logger:** create parent folders if they are missing ([0d24bd9](karma-runner/karma@0d24bd9)), closes [#&#8203;3734](karma-runner/karma#3734)

#### [6.3.9](karma-runner/karma@v6.3.8...v6.3.9) (2021-11-16)

##### Bug Fixes

-   restartOnFileChange option not restarting the test run ([92ffe60](karma-runner/karma@92ffe60)), closes [#&#8203;27](karma-runner/karma#27) [#&#8203;3724](karma-runner/karma#3724)

#### [6.3.8](karma-runner/karma@v6.3.7...v6.3.8) (2021-11-07)

##### Bug Fixes

-   **reporter:** warning if stack trace contains generated code invocation ([4f23b14](karma-runner/karma@4f23b14))

#### [6.3.7](karma-runner/karma@v6.3.6...v6.3.7) (2021-11-01)

##### Bug Fixes

-   **middleware:** replace %X_UA_COMPATIBLE% marker anywhere in the file ([f1aeaec](karma-runner/karma@f1aeaec)), closes [#&#8203;3711](karma-runner/karma#3711)

#### [6.3.6](karma-runner/karma@v6.3.5...v6.3.6) (2021-10-25)

##### Bug Fixes

-   bump vulnerable ua-parser-js version ([6f2b2ec](karma-runner/karma@6f2b2ec)), closes [#&#8203;3713](karma-runner/karma#3713)

#### [6.3.5](karma-runner/karma@v6.3.4...v6.3.5) (2021-10-20)

##### Bug Fixes

-   **client:** prevent socket.io from hanging due to mocked clocks ([#&#8203;3695](karma-runner/karma#3695)) ([105da90](karma-runner/karma@105da90))

#### [6.3.4](karma-runner/karma@v6.3.3...v6.3.4) (2021-06-14)

##### Bug Fixes

-   bump production dependencies within SemVer ranges ([#&#8203;3682](karma-runner/karma#3682)) ([36467a8](karma-runner/karma@36467a8)), closes [#&#8203;3680](karma-runner/karma#3680)

#### [6.3.3](karma-runner/karma@v6.3.2...v6.3.3) (2021-06-01)

##### Bug Fixes

-   **server:** clean up vestigial code from proxy ([#&#8203;3640](karma-runner/karma#3640)) ([f4aeac3](karma-runner/karma@f4aeac3)), closes [/tools.ietf.org/html/std66#section-3](https://github.com//tools.ietf.org/html/std66/issues/section-3)

#### [6.3.2](karma-runner/karma@v6.3.1...v6.3.2) (2021-03-29)

##### Bug Fixes

-   fix running tests in IE9 ([#&#8203;3668](karma-runner/karma#3668)) ([0055bc5](karma-runner/karma@0055bc5)), closes [/github.com/karma-runner/karma/blob/026fff870913fb6cd2858dd962935dc74c92b725/client/main.js#L14](https://github.com//github.com/karma-runner/karma/blob/026fff870913fb6cd2858dd962935dc74c92b725/client/main.js/issues/L14) [#&#8203;3665](karma-runner/karma#3665)

#### [6.3.1](karma-runner/karma@v6.3.0...v6.3.1) (2021-03-24)

##### Bug Fixes

-   **client:** clearContext after complete sent ([#&#8203;3657](karma-runner/karma#3657)) ([c0962e3](karma-runner/karma@c0962e3))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1412
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
anthony-redFox pushed a commit to anthony-redFox/karma that referenced this issue May 16, 2023
Node 17+ changed the DNS resolution (see nodejs/node#40702), so now it resolves `localhost` according to the OS settings instead of IPv4-address first. The Karma server only listens on IPv4 address (127.0.0.1) by default, but the requests are sent to `localhost` in several places and `localhost` is resolved into IPv6 address (`::`) in Node 17+. So the run/stop/proxy request is unable to reach the Karma server and produces an error. This commit configures karma to use the IPv4-address first approach in newer Node version as well.

In the future major release, we may consider changing defaults to listen on IPv6 address instead, but IPv6 is not supported in Docker on macOS and Windows, so I think we should not rush such a change to make sure karma works there out of the box.

Fixes karma-runner#3730
anthony-redFox pushed a commit to anthony-redFox/karma that referenced this issue May 16, 2023
## [6.3.20](karma-runner/karma@v6.3.19...v6.3.20) (2022-05-13)

### Bug Fixes

* prefer IPv4 addresses when resolving domains ([e17698f](karma-runner@e17698f)), closes [karma-runner#3730](karma-runner#3730)
simpleigh added a commit to simpleigh/touch-pricker that referenced this issue Aug 7, 2023
### Why?

```
07 08 2023 18:16:36.397:INFO [karma-server]: Karma v6.4.2 server started at http://localhost:9876/
07 08 2023 18:16:36.398:INFO [launcher]: Launching browsers jsdom with concurrency unlimited
07 08 2023 18:16:36.402:INFO [launcher]: Starting browser jsdom
07 08 2023 18:16:36.421:ERROR [karma-server]: UnhandledRejection: Error: connect ECONNREFUSED ::1:9876
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)
07 08 2023 18:16:36.422:ERROR [karma-server]: Error: connect ECONNREFUSED ::1:9876
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 9876
}
error Command failed with exit code 1.
```

> The Karma server only listens on IPv4 address (`0.0.0.0`) by default,
> but the requests are sent to `localhost` and `localhost` is resolved
> into IPv6 address (`::`) in Node 17+. So the run request is unable to
> reach the Karma server.

### References

* http://karma-runner.github.io/6.4/config/configuration-file.html#listenaddress
* karma-runner/karma#3730 (comment)
simpleigh added a commit to simpleigh/touch-pricker that referenced this issue Aug 7, 2023
### Why?

```
07 08 2023 18:16:36.397:INFO [karma-server]: Karma v6.4.2 server started at http://localhost:9876/
07 08 2023 18:16:36.398:INFO [launcher]: Launching browsers jsdom with concurrency unlimited
07 08 2023 18:16:36.402:INFO [launcher]: Starting browser jsdom
07 08 2023 18:16:36.421:ERROR [karma-server]: UnhandledRejection: Error: connect ECONNREFUSED ::1:9876
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16)
07 08 2023 18:16:36.422:ERROR [karma-server]: Error: connect ECONNREFUSED ::1:9876
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 9876
}
error Command failed with exit code 1.
```

> The Karma server only listens on IPv4 address (`0.0.0.0`) by default,
> but the requests are sent to `localhost` and `localhost` is resolved
> into IPv6 address (`::`) in Node 17+. So the run request is unable to
> reach the Karma server.

### References

* http://karma-runner.github.io/6.4/config/configuration-file.html#listenaddress
* karma-runner/karma#3730 (comment)
ljowen added a commit to TerriaJS/terriajs that referenced this issue Apr 9, 2024
ljowen added a commit to TerriaJS/terriajs that referenced this issue Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment