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.

EADDRINUSE errors when tests run concurrently

See original GitHub issue

We have multiple tests in our test suite that depend on mockttp, making use of its capability to randomly assign a port, and when Jest runs these tests concurrently we occasionally see errors in the form:

listen EADDRINUSE: address already in use :::8000
      at MockttpServer.<anonymous> (node_modules/mockttp/src/server/mockttp-server.ts:138:22)            
      at fulfilled (node_modules/mockttp/dist/server/mockttp-server.js:8:58)

To reproduce this issue we set up the following test:

import { getLocal } from 'mockttp';

describe('mockttp tests running in parallel', () => {
    const mockServer = getLocal();

    beforeAll(async () => {
        await mockServer.start();
    });

    afterAll(async () => await mockServer.stop());

    it('should pass', () => {
        expect(true).toBe(true);
    });
});

and then executed:

printf %s\\n {0..64} | xargs -n 1 -P 16 npx jest <test-name>

to run 16 instances of the test in parallel (on our 16 core machine) 4 times in a row. On most runs we see this issue occurring.

Can we introduce some kind of locking or retry mechanism in mockttp-server.start, or do you think we’re using the library in a way it wasn’t intended to be used?

Tested on version 0.21.2.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pimterrycommented, Aug 28, 2020

This is now published as v1.0.1 👍

1reaction
pimterrycommented, Aug 21, 2020

This has now been released, as part of Mockttp 1.0.0 🎉. Enjoy, let me know if you have any other trouble.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node, React, with concurrently, EADDRINUSE :::8000 error
When I execute yarn dev I get the following error: $ concurrently "yarn server" "yarn client" $ nodemon index.js $ yarn start --prefix...
Read more >
EADDRINUSE error when running node integration tests
It's my understanding that while Jest runs the tests within each file sequentially, it runs the different test files in parallel. It seems...
Read more >
How to kill server when seeing “EADDRINUSE: address ...
When this EADDRINUSE issue has already happened, in order to resolve it, you need to kill the process manually. In order to do...
Read more >
listen EADDRINUSE: address already in use :::5000-node.js
Coding example for the question node:events:304 Error: listen EADDRINUSE: ... I changed "dev": "concurrently \"yarn run server\" \"yarn run client\"" to ...
Read more >
EADDRINUSE when watching tests with mocha and supertest
The problem happens when we run tests without closing the server, as is the case when we are watching our tests. Like I...
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