-
Notifications
You must be signed in to change notification settings - Fork 25
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
Expose stoppable.increment and stoppable.decrement #9
base: master
Are you sure you want to change the base?
Conversation
readme.md
Outdated
server.stoppable.increment(socket) | ||
``` | ||
|
||
Increment a counter for a specified socket. This method returns a new counter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "a new counter" mean? The new "current count" of the socket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the incremented pending count of the specified socket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps rephrase to "This method returns the new count." or something like that? Apparently I guessed right, but it really was a guess :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing it out. Updated.
@hunterloftis Is there any chance for this PR to be merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need some tests, but also: can you please explain more about why this change is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need some tests, but also: can you please explain more about why this change is necessary?
@boneskull With normal HTTP requests, stoppable can determine whether a server is processing requests or not. I mean, it can think a server starts processing after On the other hand, when it comes to WebSocket, there are no clear definitions when a server is processing. For example, imagine you're designing an application using WebSocket, and decided a server sends two WebSocket messages when it receives one WebSocket message from a client. In this case, you don't want to shutdown the server after it sends the first message but before sending the second one. So it's up to an application if a server can be shutdown gracefully. To tell stoppable whether it can stop the server gracefully, we need help from an application, hence these new APIs. |
Note: if an application can hang the server unless correctly configured, I'd question the server design. It should be possible (using another codebase) to close the other connections separately, or just force quit the server after |
I'm using stoppable with WebSocket. Since stoppable itself doesn't handle WebSocket (and it's impossible for stoppable itself to know when it can shutdown), I manually manipulate
server._pendingSockets
and close connections in my code. But I'm not comfortable depending on private APIs.This patch exposes two new methods (stoppable.increment and stoppable.decrement) from a server. With these methods, I can tell stoppable from my code when is appropriate to shutdown.