-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add override for default closeTimeout. #2308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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. |
Setting the option closeTimeout will override the default milliseconds for terminating unresponsive connections.