This repo demonstrates and reproduces an outstanding issue with Nodemon. To reliably produce this issue, the following criteria must be met:
- Nodemon must be running in a Docker container.
- The
--inspect
flag must be passed. - The application must register an asynchronous listener for the
SIGUSR2
signal to handle shutting down, and this function must take some non-trivial amount of time to run.
When run outside of Docker (ie: conditions 2 and 3 are still met), Nodemon works as expected and will wait for the shutdown handler to finish, and for the process to exit, before starting a new process.
However, when run in Docker, Nodemon will attempt to start a new process immediately, without waiting for the current process to exit. Because we are using the Node debugger, the new process will attempt to open a server on a port that is still in use by the previous process, causing the new process to immediately crash.
To demonstrate the differences between these two behaviors, you may run npm start
to run this application on the host machine, and npm run start:docker
to run it in a Docker container.
This was tested with the following software:
$ node -v
v10.13.0
$ docker -v
Docker version 18.09.0, build 4d60db4
$ docker-compose -v
docker-compose version 1.23.1, build b02f1306