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

[Question]: Order of requests in capnp-rpc #528

Closed
SteveLauC opened this issue Nov 11, 2024 · 3 comments
Closed

[Question]: Order of requests in capnp-rpc #528

SteveLauC opened this issue Nov 11, 2024 · 3 comments

Comments

@SteveLauC
Copy link
Contributor

Hi, thanks for the work on the project!

I would like to know the answers to the following questions:

  1. With only 1 connection between client and server, does capnp-rpc preserve the order in which requests are sent? i.e., the first request will be handled first.
  2. With only 1 connection between client and server, if multiple requests of the same RPC interface arrive in order, will they be handled sequentially? If these requests belong to different RPC interfaces, will they be handled sequentially as well? I guess the answer to both questions is yes because capnp-rpc is runtime-agnostic and does not "spawn()" things
@dwrensha
Copy link
Member

  1. With only 1 connection between client and server, does capnp-rpc preserve the order in which requests are sent?

capnp-rpc is supposed to deliver messages in the order they were received: capnproto/capnproto#1862 (comment)

However, there are some known issues. For example, promise resolution over a two-hop connection could break ordering (#529). Moreover, we currently depend on the task scheduler (tokio usually) being first-in-first-out:

// We don't want to actually dispatch the call synchronously, because we don't want the callee
// to have any side effects before the promise is returned to the caller. This helps avoid
// race conditions.
//
// TODO: actually use some kind of queue here to guarantee that call order is maintained.
// This currently relies on the task scheduler being first-in-first-out.
let inner = self.inner.clone();
Promise::from_future(async move {

  1. With only 1 connection between client and server, if multiple requests of the same RPC interface arrive in order, will they be handled sequentially?

Method calls are initiated sequentially (each call gets access to &mut self, so this must be the case). If a call returns a future constructed with Promise::from_future(), then the remaining action represented by that future can take place concurrently (interleaved) with other calls. For example, if a method body returns Promise::from_future(future::pending()) then the call never terminates (the client never gets a response), but other calls can still take place unobstructed.

@dwrensha
Copy link
Member

Closing because this is a question not an issue. In the future, please use https://github.com/capnproto/capnproto-rust/discussions for this kind of thing.

@SteveLauC
Copy link
Contributor Author

Thanks for answering the question!

In the future, please use https://github.com/capnproto/capnproto-rust/discussions for this kind of thing.

Sorry for using issue for questions 😵, I will use discussion next time.

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