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

Fix broken client request routing and loosen trait bounds #184

Merged
merged 2 commits into from
Apr 30, 2020

Conversation

ebkalderon
Copy link
Owner

Changed

  • Remove one internal use of tokio::spawn() in favor of futures::join!() (see Avoid calling tokio::spawn internally #180).
  • Allow !Send and !'static streams and IO handles to be used with Server.
  • Update stdio.rs tests to take &mut stdin and &mut stdout and inspect the two buffers afterwards for correctness. This one was a long time coming!

Fixed

  • Fix bidirectional request routing by using buffer_unordered().

It seems that server-to-client request routing (introduced in #134) was broken because of service.call(request).await in Server blocking forever, preventing the response from being routed back to the awaiting RPC handler. This commit fixes this issue, while also removing some strict trait bounds on the stdin and stdout handles, as well as the interleave stream, and decoupling us a tiny bit further from tokio.

Fixes #183.

It seems that the previous implementation of server-to-client request
routing was broken because of `service.call(request).await` in `Server`
blocking forever, preventing the response from being routed back to the
awaiting RPC handler.

This commit fixes this by rewriting `Server::serve() to use
`buffer_unordered()` to drive at least 4 concurrent futures at the
same time, thereby avoiding stalling the executor and enabling proper
multiplexing of client-to-server and server-to-client communication.

As a bonus, we also eliminate one use of `tokio::spawn()` by using
`futures::join!()` to drive the printer and reader futures concurrently
without depending on a threaded executor. This is a nice step towards
eventually decoupling from `tokio`.
This has been a long-standing issue resulting from the strict
requirements imposed by the `tokio::spawn()` call in `Server::serve()`.
But now that we rely on `join!()` to drive both futures to completion
without having to deal with the complexities of a multi-threaded
executor, we no longer require that the interleaved stream and
`AsyncRead`/`AsyncWrite` handles be `Send + 'static`.

This finally allows us to update the `stdio.rs` tests to take mock
`stdin` and `stdout` handles as `&mut`, allowing us to inspect the final
state once the test is done and the `Server` has shut down.
@ebkalderon ebkalderon self-assigned this Apr 30, 2020
@ebkalderon ebkalderon merged commit 975a6b6 into master Apr 30, 2020
@ebkalderon ebkalderon deleted the fix-client-request-routing branch April 30, 2020 05:24
@ebkalderon ebkalderon changed the title Fix broken client request routing and loosen trait bonuds Fix broken client request routing and loosen trait bounds Apr 30, 2020
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.

Client request routing is broken
1 participant