fix(pool): Singleton shared calls pass baton if one cancels#299
Open
seanmonstar wants to merge 1 commit into
Open
fix(pool): Singleton shared calls pass baton if one cancels#299seanmonstar wants to merge 1 commit into
seanmonstar wants to merge 1 commit into
Conversation
Contributor
|
Pulled the branch and ran it against the maker-future-dropped case (driver's future dropped mid-make): the surviving waiter inherits the drive and connects, where master resolves Canceled. Also confirmed the existing UseOther-bounce cancellation from #4119 stays fixed. LGTM. One additive coverage note: the existing cancellation tests promote a waiter that was registered but not yet polled (its stored waker is None). The path where an already-polled, parked waiter is promoted on driver drop, where the promotion carries a stored Waker, isn't exercised (I think). #[tokio::test]
async fn cancel_driver_promotes_parked_waiter() {
let (mock_svc, mut handle) = tower_test::mock::pair::<(), &'static str>();
let mut singleton = Singleton::new(mock_svc);
std::future::poll_fn(|cx| singleton.poll_ready(cx)).await.unwrap();
let mut fut1 = singleton.call(()); // driver
let mut fut2 = singleton.call(()); // waiter
// Poll both once so the waiter parks with a stored waker (not just registered).
std::future::poll_fn(|cx| {
assert!(Pin::new(&mut fut1).poll(cx).is_pending());
assert!(Pin::new(&mut fut2).poll(cx).is_pending());
Poll::Ready(())
})
.await;
drop(fut1); // promote the parked waiter to driver
let ((), send_response) = handle.next_request().await.unwrap();
send_response.send_response("svc");
fut2.await.unwrap();
} |
5ab3a53 to
c1c57af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, with a bunch of calls all funneled into a
Singleton, the first call was the "driver", and the rest all waited for the driver to finish and send a clone to them. The downside is that if the first call canceled, all the subsequent waiters would just get a "canceled" error.This changes to a baton-passing strategy. If the first future gets canceled, it passes the baton to keep driving the future to one of the other waiters. Only once all of them are canceled will it cancel the connection attempt.
cc @aajtodd