creesch / discordIRCd

A node.js script that allows you to connect to discord with your irc client.
Apache License 2.0
116 stars 21 forks source link

Clean up port after SIGINT (Ctrl+C) #23

Closed Scrxtchy closed 7 years ago

Scrxtchy commented 7 years ago

Common issue I have after stopping the server to restart it / git pull After giving it a graceful shutdown via a SIGINT, the port still seems to be in use for another couple of minutes. Due to this, an error is thrown

Error: listen EADDRINUSE :::34416
    at Object.exports._errnoException (util.js:1028:11)
    at exports._exceptionWithHostPort (util.js:1051:20)
    at Server._listen2 (net.js:1261:14)
    at listen (net.js:1297:10)
    at Server.listen (net.js:1375:9)
    at Client.<anonymous> (/mnt/mpathag/scratch/node/discordIRCd/server.js:320:19)
    at emitNone (events.js:91:20)
    at Client.emit (events.js:186:7)
    at WebSocketManager._emitReady (/mnt/mpathag/scratch/node/discordIRCd/node_modules/discord.js/src/client/websocket/WebSocketManager.js:325:17)
    at Promise.all.then (/mnt/mpathag/scratch/node/discordIRCd/node_modules/discord.js/src/client/websocket/WebSocketManager.js:344:49)

Seems to already have a stackoverflow thread since it's common appearance, ...six years ago https://stackoverflow.com/questions/4075287/node-express-eaddrinuse-address-already-in-use-kill-server I'm still unsure on the correct approach to a fix though

creesch commented 7 years ago

This really shouldn't be an issue as I literally already do this. Look at the bottom of server.js

No clue why it isn't working for you though.

Scrxtchy commented 7 years ago

Could be that ZNC is trying to keep it alive https://nodejs.org/api/net.html#net_server_close_callback

creesch commented 7 years ago

Right. I'll also make sure all sockets are closed.

Scrxtchy commented 7 years ago
Gracefully shutting down from SIGINT (Ctrl-C)
/mnt/mpathag/scratch/node/discordIRCd/server.js:1452
        socket.close()
               ^

TypeError: socket.close is not a function
    at /mnt/mpathag/scratch/node/discordIRCd/server.js:1452:16
    at Array.forEach (native)
    at process.<anonymous> (/mnt/mpathag/scratch/node/discordIRCd/server.js:1451:16)
    at emitNone (events.js:86:13)
    at process.emit (events.js:186:7)
    at Signal.wrap.onsignal (internal/process.js:200:44)

I don't get it But it looks like it's working

creesch commented 7 years ago

Oh that still might be an error. Let's see if I can make that go away.