docker-lambda icon indicating copy to clipboard operation
docker-lambda copied to clipboard

Address Already In Use Error During Jest Tests

Open victormonterrosoqb opened this issue 5 years ago • 1 comments

When trying to run a suite of jest unit tests I get repeated errors saying

Error: listen tcp 127.0.0.1:9001: bind: address already in use"

My first test will always succeed but subsequent ones all fails. Since Jest runs all tests in parallel (I tried using --runInBand which did not help), I suspect that is what is causing this error. How can this be fixed?

victormonterrosoqb avatar Jan 17 '20 17:01 victormonterrosoqb

Are you exposing that port to your tests or doing anything unusual with your docker networking? Each Lambda needs that port for communication, so if you're not isolating them, then they'll all be trying to listen on the same port and you'll get the error you're seeing.

Depending on whether you're developing using DOCKER_LAMBDA_STAY_OPEN or not, you can modify this port with the DOCKER_LAMBDA_RUNTIME_PORT and/or DOCKER_LAMBDA_API_PORT options as described here: https://github.com/lambci/docker-lambda#running-in-stay-open-api-mode – so you could assign a custom port to each test.

mhart avatar Jan 17 '20 17:01 mhart