sitegui / nodejs-websocket

A node.js module for websocket server and client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server.close() missing

rikelme opened this issue · comments

commented

Server doesn't expose close() method

Hello @rikelme ,

You're right, this lib does not offer a clean shutdown of a server.

You can do a dirty close with server.socket.close(). It's dirty because the closing handshake from the spec will not be performed (but it will work nonetheless).

Or you can close all connections first and then the server:

async.each(server.connections, (conn, done) => conn.close(done), () => server.close())

But this is only half the solution, since new connections accepted while the old ones were being closed won't shutdown smoothly.

Any ideas or Pull Request in this direction will be welcomed ;)

Best regards

commented

Hey @sitegui,

Just add a 'closing' flag variable in a Server and ignore new connections if it's set to true.

Cheers

I had misread the way node works. Paying more attention to the docs now:

Stops the server from accepting new connections and keeps existing connections. This function is asynchronous, the server is finally closed when all connections are ended and the server emits a 'close' event. The optional callback will be called once the 'close' event occurs.

That means server.socket.close() is not dirty at all, since no client connection will be closed.