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

Should BoxFuture/BoxStream require Sync? #1752

Closed
Nemo157 opened this issue Jul 20, 2019 · 3 comments
Closed

Should BoxFuture/BoxStream require Sync? #1752

Nemo157 opened this issue Jul 20, 2019 · 3 comments

Comments

@Nemo157
Copy link
Member

Nemo157 commented Jul 20, 2019

I was just looking at testing integrating some code with Hyper's master branch. The first problem I came across was that the existing code uses BoxStream to represent its body type, which cannot be converted into hyper::Body because it additionally wants Sync on the trait object:

pub fn wrap_stream<S>(stream: S) -> Body
where
    S: TryStream + Send + Sync + 'static,
    S::Error: Into<Box<dyn StdError + Send + Sync>>,
    Chunk: From<S::Ok>, 

I don't see why Sync would be necessary, since I see no usecases where the type is accessed concurrently from different threads, but it seems to be pretty common to require both markers for trait objects (e.g. there is Into<Box<dyn Error + Send + Sync>> but not Into<Box<dyn Error + Send>> which I have run into, and seen others run into, multiple times).

I can't think of any Send + !Sync type right now, and it seems like a niche usecase if they do exist.

cc @seanmonstar

@12101111
Copy link

hyper require Sync on this method since hyperium/hyper@4441372
Because rust-lang/rust#57017
Maybe it’s a bug in rustc

@Nemo157
Copy link
Member Author

Nemo157 commented Jul 22, 2019

More specifically the bug that Hyper is running into appears to be rust-lang/rust#59245 (via rust-lang/rust#57017 causing the match patterns to create unnecessary references, but it would still be possible to hit #59245 without #57017).

It seems to me that it's definitely a bug in the generator transform, if the reference is internal then there's no need for the referenced value to be Sync.

Either way, is there a downside to adding + Sync here? Skimming the docs I notice that Cell, RefCell and mpsc::{Receiver, Sender} appear to be the only types that are Send + !Sync.

@cramertj
Copy link
Member

We now have LocalBoxFuture and LocalBoxStream which I believe resolve this issue. Let me know if there is more wanted here!

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

3 participants