Skip to content

fix(tonic): make Streaming Sync again #2293

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

Merged
merged 1 commit into from
Jun 20, 2025

Conversation

Twey
Copy link
Contributor

@Twey Twey commented Jun 4, 2025

Motivation

The boxed Decoder and Body inside Streaming need not be Sync since #804. Unfortunately, that makes Streaming non-Sync, meaning that all the generated tonic futures cannot be awaited in Sync futures, i.e. it regresses #81.

Solution

In fact, the only times we use self.decoder or self.body, we have a &mut unique reference to it, so we are guaranteed not to require synchronization.

The sync_wrapper crate encodes this reasoning, allowing us to safely make the Streaming type Sync regardless of whether the contained Decoder and Body are Sync or not.

@Twey Twey force-pushed the sync-streaming branch from c6eb817 to b65a7c7 Compare June 4, 2025 16:14
@Twey Twey marked this pull request as draft June 4, 2025 16:15
@Twey Twey force-pushed the sync-streaming branch from b65a7c7 to 0772ead Compare June 4, 2025 16:22
The boxed `Decoder` inside `Streaming` need not be `Sync` since
hyperium#804.  Unfortunately, that makes
`Streaming` non-`Sync`, meaning that all the generated `tonic` futures
cannot be awaited in `Sync` futures.

In fact, the only times we use the `Decoder`, we have a `&mut` unique
reference to it, so we are guaranteed not to require synchronization.

The `sync_wrapper` crate encodes this reasoning, allowing us to safely
make the `Streaming` type `Sync` regardless of whether the contained
`Decoder` is `Sync` or not.
@LucioFranco
Copy link
Member

Thanks

@LucioFranco LucioFranco merged commit 87d2d4c into hyperium:master Jun 20, 2025
32 of 34 checks passed
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.

3 participants