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

Handle backpressure and remove ExitReceiver #117

Merged
merged 3 commits into from
Feb 28, 2020

Conversation

ebkalderon
Copy link
Owner

Changed

  • Return Err from LspService::poll_ready() if the exit notification is received.
  • Gracefully shut down the Server once the underlying service's poll_ready() returns Err.

Removed

  • Remove ExitReceiver and LspService::close_handle().

According to the [docs] for `tower_service::Service::poll_ready()`, the
method implementation is supposed to return `Poll::Ready(Err(_))` if the
service in question is no longer able to accept requests. In our current
implementation, we return `Poll::Pending`, which is semantically
incorrect.

[docs]: https://docs.rs/tower-service/0.3.0/tower_service/trait.Service.html#tymethod.poll_ready

This changes our `poll_ready()` implementation to conform with the
upstream interface specification so we can properly handle backpressure.
This adapts `Server` to properly handle service backpressure by awaiting
on `Service::poll_ready()` and exiting early if the underlying service
returns `Poll::Ready(Err(_))`. This should make the `Server` shut itself
down gracefully once it detects that the underlying service is no longer
able to serve requests.
A nice side effect of the previous `poll_ready()` changes: since the
`Server` now shuts itself automatically as soon as the underlying
service returns a `Poll::Ready(Err(_))`, there is no reason to keep
`ExitReceiver` around anymore.

This allows users to await the `Server::serve()` future directly, which
improves the API ergonomics quite a bit and allows us to get rid of
`ExitReceiver` entirely.
@ebkalderon ebkalderon self-assigned this Feb 28, 2020
@ebkalderon ebkalderon merged commit 56d8a9d into master Feb 28, 2020
@ebkalderon ebkalderon deleted the implement-backpressure branch February 28, 2020 12:10
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

Successfully merging this pull request may close these issues.

1 participant