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

EADDRINUSE error leads to improper port usage by server middleware #3011

Closed
sergei-startsev opened this issue May 22, 2018 · 7 comments · May be fixed by Omrisnyk/npm-lockfiles#122 or Omrisnyk/npm-lockfiles#132

Comments

@sergei-startsev
Copy link
Contributor

Expected behaviour

If a port is changed in the passed configuration before server start (e.g. if EADDRINUSE is thrown for a specified port, the next available is used), it should be respected by server middleware.

Actual behaviour

Middleware use a port that was initially passed in the configuration.

Environment Details

  • Karma version (output of karma --version): reproduced in 1.7.1, but should be also actual for 2.0.2
  • Relevant part of your karma.config.js file: proxy middleware can be used as an example
proxies: {
  '/img/': '/base/test/images/'
},
port: <specify already used port>

Steps to reproduce the behaviour

  1. Run karma instance (karma start) with already used port – in other words you have to raise EADDRINUSE error in
    if (e.code === 'EADDRINUSE') {
    It can be reproduced by running 2 or more karma instances that use the same port (e.g. 9876)
  2. You have to see Karma warning: WARN [karma]: Port 9876 in use
    and a new port that Karma uses: INFO [karma]: Karma <v> server started at http://0.0.0.0:9877/

image

  1. Try to load any resources that match proxy rules.
  2. Resources are proxied to the initial port 9876 instead of changed 9877.
@EzraBrooks
Copy link
Collaborator

This seems to be (as you can see in the linked source snippet) intentional behavior. I would agree with you that it's not very intuitive - when you tell an application to use a port, it should use it or fail. Changing this would be, I assume, a reversal of a design decision, so it'll probably require some discussion.

@sergei-startsev
Copy link
Contributor Author

As far as I can see 58caccd was intended to prevent karma fail if a current port is already in use, there was assumption that the next available port will be used by karma as well as karma middleware and other karma modules. Here's an open bug that looks related to this one #1476.

Does @dignifiedquire proposal still look reasonable here?

@lusarz lusarz closed this as completed in a19b8d4 Jun 15, 2018
@ViieeS
Copy link

ViieeS commented Jun 26, 2018

@lusarz it's not fixed for me

karma v2.0.4

image

@lusarz
Copy link
Contributor

lusarz commented Jun 26, 2018

@ViieeS is it Karma v2.0.4 ?

@ViieeS
Copy link

ViieeS commented Jun 26, 2018

@lusarz yes. I have 3 pipelines running in the same time in gitlab. v2.0.2 works fine.

@lusarz
Copy link
Contributor

lusarz commented Jun 26, 2018

@ViieeS
True, I probably know what happened, but I'm not sure how to fix it smartly.

I check for available port a lot before real karma server starts to run (fileList.refresh may take some time), so for every pipeline started at same time, NetUtils.getAvailablePort returns 9876.

.then(() => NetUtils.getAvailablePort(config.port, config.listenAddress))

fileList.refresh().then(afterPreprocess, afterPreprocess)

webServer.listen(config.port, config.listenAddress, () => {

I'll try to think about solution in nearest future. As a workaround please revert to v2.0.2, or try to configure port separately for every pipeline in gitlab.

@ViieeS
Copy link

ViieeS commented Jun 26, 2018

@lusarz got it, thanks! Somehow needs to bind the port right away after checking. Hope you can fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants