Skip to content
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

Different graceful shutdown behavior for websockets? #839

Open
thomasjm opened this issue Mar 4, 2021 · 2 comments
Open

Different graceful shutdown behavior for websockets? #839

thomasjm opened this issue Mar 4, 2021 · 2 comments
Assignees

Comments

@thomasjm
Copy link
Contributor

thomasjm commented Mar 4, 2021

The documentation for setGracefulShutdownTimeout explains how Warp enters a graceful shutdown mode when the server socket is closed. If a non-Nothing timeout is installed, the server will wait for the timeout for requests to finish up before shutting down the server.

This behavior makes sense for regular HTTP requests, which can be expected to finish up at some point. It doesn't work as well for websocket connections established via wai-websockets, because a websocket can stay open indefinitely. Thus, if the server has no graceful shutdown timeout it will stay in the shutdown state indefinitely. Or, if it does have a timeout, it will eventually tear down the websocket connection non-gracefully. (WebSocket peers are supposed to send a close message before closing the connection.)

I'm not sure what the best solution would be, but maybe a "server is shutting down" exception could be thrown to all existing websocket handlers, which they could catch use to close down gracefully?

@kazu-yamamoto kazu-yamamoto self-assigned this May 21, 2021
@kazu-yamamoto
Copy link
Contributor

Sorry for the delay.

Let's talk about the exception approach. I guess that threads for web socket are willing to accept the exception but other threads are not because waiting for timeout. How to distinguish these two types of threads?

@thomasjm
Copy link
Contributor Author

Sorry @kazu-yamamoto, I thought I responded to this already.

I was thinking that since wai-websockets lives in this same repo, there must be some way it can communicate with Warp that it's running a WebSocket thread. Might be tricky because this communication would have to happen through the WAI abstraction.

For example (just thinking out loud here) maybe Warp could provide some callback registerForServerShutdownException which a thread can use to register for these exceptions, and that callback gets passed to the websocketsOr function and called there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants