arduino / arduino-ide

Arduino IDE 2.x
https://www.arduino.cc/en/software
GNU Affero General Public License v3.0
2.35k stars 394 forks source link

TCP port 50051 remains in use after unclean IDE exit #654

Open ckuethe opened 3 years ago

ckuethe commented 3 years ago

Describe the bug Arduino-ide can leave behind something listening on port 50051 if the gui exits uncleanly

...
daemon INFO Restarting daemon in 5 seconds...
daemon INFO Failed to listen on TCP port: 50051. Address already in use.
daemon INFO Daemon exited with exit code: 5.
daemon INFO Restarting daemon in 4 seconds...
daemon INFO Restarting daemon in 3 seconds...
daemon INFO Restarting daemon in 2 seconds...
daemon INFO Restarting daemon in 1 seconds...
daemon INFO Restarting daemon now...
daemon INFO Starting daemon from /home/opt/arduino-ide_2.0.0-rc1_Linux_64bit/resources/app/node_modules/arduino-ide-extension/build/arduino-cli...
daemon INFO Using config file: /home/ckuethe/.arduinoIDE/arduino-cli.yaml
daemon INFO arduino-cli version 0.20.1
daemon INFO Executing `arduino-cli daemon`
daemon INFO Setting up Prometheus metrics on :9090/metrics
daemon INFO Starting daemon on TCP address 127.0.0.1:50051
daemon ERROR listen tcp :9090: bind: address already in use
daemon ERROR Failed to listen on TCP port: 50051. Address already in use.
daemon INFO Failed to start the daemon.
daemon ERROR Error: Failed to listen on TCP port. Address already in use.
    at Function.parse (/home/opt/arduino-ide_2.0.0-rc1_Linux_64bit/resources/app/node_modules/arduino-ide-extension/lib/node/arduino-daemon-impl.js:244:24)
    at Socket.<anonymous> (/home/opt/arduino-ide_2.0.0-rc1_Linux_64bit/resources/app/node_modules/arduino-ide-extension/lib/node/arduino-daemon-impl.js:143:43)
    at Socket.emit (events.js:223:5)
    at addChunk (_stream_readable.js:309:12)
    at readableAddChunk (_stream_readable.js:290:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:181:23)
...

To Reproduce Steps to reproduce the behavior:

  1. in a terminal /path/to/arduino-ide 2>&1 | tee /tmp/arduino-log-1
  2. get annoyed at how long startup takes
  3. kill the process with^C
  4. /path/to/arduino-ide 2>&1 | tee /tmp/arduino-log-2
  5. observe the listen failure

Expected behavior Either clean up all processes on the way out, or try to reuse existing arduino-cli process

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

per1234 commented 3 years ago

There is a related discussion at https://github.com/arduino/arduino-ide/issues/201 about how the IDE or Arduino CLI can avoid or improve the user experience in the event of a port collision.

Even though related, this issue is not a duplicate of https://github.com/arduino/arduino-ide/issues/201 because this issue is about the former use of the IDE itself being the cause of the collision rather than some expected collision with another application using 50051 (e.g., Multipass).