Add override for default closeTimeout.#2308
Conversation
|
If added the option should also work on the server, but is there a good reason to add it? It is already possible to call |
|
It is possible to call websocket.terminate() but what i want to do is the same thing as closeTimer. I want to leverage the existing code to close sooner than 30 seconds. I need it for the server to force clients to close when they don't respond. I like it as an option because you could run multiple websocket servers with different needs. One might be more active and need to close clients sooner. |
Yes, you can do something like this: const timer = setTimeout(() => { ws.terminate(); }, 3000);
ws.on('close', () => { clearTimeout(timer); });
ws.close(); You also need to run something like https://github.com/websockets/ws?tab=readme-ov-file#how-to-detect-and-close-broken-connections regardless of this change. At the moment you made the option only work on the client. |
b5060af to
bb60b5b
Compare
|
Sorry i only had a test on the client. Thank you for the updated test for client and server. That works for me. |
|
Any comment on #2308 (comment)? Does that work for you? |
|
If the thumbs-up means it's enough for you, I'll wait a little while to see if anyone else is interested in this option, otherwise I'll close this PR. |
|
Thank you for fixing this. |
Make graceful close timeout configurable.
Setting the option closeTimeout will override the default milliseconds for terminating unresponsive connections.