HeyPuter / terminal

⌨️ Web-based terminal in pure JavaScript
https://puter.com/app/terminal
GNU Affero General Public License v3.0
113 stars 15 forks source link

dev-runner leaves sockets in use after quitting #3

Open AtkinsSJ opened 6 months ago

AtkinsSJ commented 6 months ago

I'm running on Linux, and this happens a bit inconsistently for me.

Steps:

  1. dev-runner ./run-phoenix-http.json5
  2. Enter stop to shut it down
  3. Wait until all node processes related to it have exited
  4. dev-runner ./run-phoenix-http.json5 again
  5. See errors in the log about the addresses being in use.
❯ dev-runner ./run-phoenix-http.json5

src/main.js → dist/bundle.js...
created dist/bundle.js in 602ms

src/main_puter.js → dist/bundle.js...
created dist/bundle.js in 516ms
[term.http:err] node:events:497
[term.http:err]       throw er; // Unhandled 'error' event
[term.http:err]       ^
[term.http:err] 
[term.http:err] Error: listen EADDRINUSE: address already in use 0.0.0.0:8082
[term.http:err]     at Server.setupListenHandle [as _listen2] (node:net:1893:16)
[term.http:err]     at listenInCluster (node:net:1941:12)
[term.http:err]     at doListen (node:net:2096:7)
[term.http:err]     at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
[term.http:err] Emitted 'error' event on Server instance at:
[term.http:err]     at emitErrorNT (node:net:1920:8)
[term.http:err]     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[term.http:err]   code: 'EADDRINUSE',
[term.http:err]   errno: -98,
[term.http:err]   syscall: 'listen',
[term.http:err]   address: '0.0.0.0',
[term.http:err]   port: 8082
[term.http:err] }
[term.http:err] 
[term.http:err] Node.js v21.6.2
[term.http] STOPPED
[shell.rollup:err] rollup v3.21.4
[shell.rollup:err] bundles src/main_puter.js → dist/bundle.js...
[term.rollup:err] rollup v3.23.0
[term.rollup:err] bundles src/main.js → dist/bundle.js...
[shell.http:err] node:events:497
[shell.http:err]       throw er; // Unhandled 'error' event
[shell.http:err]       ^
[shell.http:err] 
[shell.http:err] Error: listen EADDRINUSE: address already in use 0.0.0.0:8080
[shell.http:err]     at Server.setupListenHandle [as _listen2] (node:net:1893:16)
[shell.http:err]     at listenInCluster (node:net:1941:12)
[shell.http:err]     at doListen (node:net:2096:7)
[shell.http:err]     at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
[shell.http:err] Emitted 'error' event on Server instance at:
[shell.http:err]     at emitErrorNT (node:net:1920:8)
[shell.http:err]     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
[shell.http:err]   code: 'EADDRINUSE',
[shell.http:err]   errno: -98,
[shell.http:err]   syscall: 'listen',
[shell.http:err]   address: '0.0.0.0',
[shell.http:err]   port: 8080
[shell.http:err] }
[shell.http:err] 
[shell.http:err] Node.js v21.6.2
[shell.http] STOPPED

After doing the same again, I only had the :8080 server fail to start. Then a third time, they both succeeded. But it definitely varies.

KernelDeimos commented 6 months ago

A few things come to mind:

AtkinsSJ commented 6 months ago

A workaround might be to scan for available ports (like the Puter dev server does) instead of hard-coding them. That doesn't fix this issue, but would make it less of a problem, and would generally be good to do as we don't know what ports someone's system might be using already.