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

Add server::Handle::shutdown #117

Merged
merged 16 commits into from
Mar 7, 2017
Merged

Add server::Handle::shutdown #117

merged 16 commits into from
Mar 7, 2017

Conversation

tikue
Copy link
Collaborator

@tikue tikue commented Feb 23, 2017

Fixes #62

Edit: as @jonhoo pointed out, this doesn't actually allow run to return right now. It just sends servers into lame duck mode, where they honor existing connections but don't accept new ones.

Edit 2: the server now shuts down after all pre-lameduck connections are closed.

Edit 3: changed to two handles: server::sync::Handle and server::future::Handle. The future one has addr() and shutdown() and the sync one has those plus run().

@tikue tikue self-assigned this Feb 23, 2017
@tikue tikue requested a review from shaladdle February 23, 2017 06:56
src/server.rs Outdated
}
});
reactor.handle().spawn(server.select(shutdown).then(|_| {
debug!("Entering lame duck mode.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?
Also, am I reading this right that the server won't actually shut down? That is, will the thread that started the server now return from the call to .run()?

Copy link
Collaborator Author

@tikue tikue Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means existing connections will be honored but no new connections will be accepted.

Yeah, so I was a bit hesitant to implement that as part of this, because it'd require one of the following, all of which I wanted to spend a bit more time thinking about and getting feedback on:

  1. Have the Handle hold the server future so that it can run it directly. Then run returns once the server stops accepting connections. This requires exposing some type parameters on Handle that are, I think, implementation details.
  2. Same as 1 but box the server to avoid type parameters. Probably not a huge performance hit since it's just boxing the top-level future, but would be better to benchmark first.
  3. Signal shutdown some other way, maybe via an AtomicBool. Not sure if there'd be any overhead in checking an atomic once per iteration of loop { reactor.turn(None); }.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to go with 2. It also means shutdown will be instantaneous rather than honoring existing connections. I think that's fine for its purpose.

Cargo.toml Outdated
@@ -15,7 +15,7 @@ description = "An RPC framework for Rust with a focus on ease of use."
travis-ci = { repository = "google/tarpc" }

[dependencies]
bincode = "1.0.0-alpha2"
bincode = { git = "https://github.com/tikue/bincode", branch = "faster-byte-buf-deserialization" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this an intentional inclusion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, thanks!

@tikue
Copy link
Collaborator Author

tikue commented Feb 24, 2017

The future::shutdown test is failing. Not sure why at the moment.

@tikue
Copy link
Collaborator Author

tikue commented Mar 1, 2017

Tokio seems to have plans to support shutdown. See tokio-rs/tokio-core#33. I don't think we need to wait for that to play out before making progress on this. We can always revisit later.

shutdown: shutdown2,
connections: connections2,
})
.map_err(Warn("UnboundedReceiver resolved to an Err; can it do that?"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any guidance from the docs about whether this can happen? If it's never supposed to resolve to an error, maybe this should be unreachable!?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I just tried replacing the () with ! in futures-rs and it still compiles, so it must never be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do it in the next PR (this file doesn't actually exist anymore)

@tikue tikue merged commit e59116f into google:master Mar 7, 2017
tikue added a commit that referenced this pull request Mar 7, 2017
@tikue tikue deleted the server-shutdown branch March 8, 2017 03:24
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.

Should server handle expose a fn for graceful shutdown?
3 participants