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

Storage: Stream is not Sync #164

Closed
thomastaylor312 opened this issue Jan 29, 2021 · 3 comments
Closed

Storage: Stream is not Sync #164

thomastaylor312 opened this issue Jan 29, 2021 · 3 comments
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved.

Comments

@thomastaylor312
Copy link

This is a follow on to #133 in which I admit I didn't read my own notes. The returned stream from the blob client does is not Sync (and not just Unpin), which limits some of its downstream use (as it can often get passed down the stack). The specific error in my case when I try to return an impl Stream + Send + Sync:

error[E0277]: `dyn Future<Output = std::result::Result<http::response::Response<bytes::Bytes>, Box<dyn StdError + Send + Sync>>> + Send` cannot be shared between threads safely
   --> src/provider/mod.rs:315:12
    |
315 |         Ok(Box::new(resp))
    |            ^^^^^^^^^^^^^^ `dyn Future<Output = std::result::Result<http::response::Response<bytes::Bytes>, Box<dyn StdError + Send + Sync>>> + Send` cannot be shared between threads safely
    |
    = help: the trait `Sync` is not implemented for `dyn Future<Output = std::result::Result<http::response::Response<bytes::Bytes>, Box<dyn StdError + Send + Sync>>> + Send`
    = note: required because of the requirements on the impl of `Sync` for `Unique<dyn Future<Output = std::result::Result<http::response::Response<bytes::Bytes>, Box<dyn StdError + Send + Sync>>> + Send>`
    = note: required because it appears within the type `Box<dyn Future<Output = std::result::Result<http::response::Response<bytes::Bytes>, Box<dyn StdError + Send + Sync>>> + Send>`
    = note: required because it appears within the type `Pin<Box<dyn Future<Output = std::result::Result<http::response::Response<bytes::Bytes>, Box<dyn StdError + Send + Sync>>> + Send>>`
    = note: required because it appears within the type `for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5> {ResumeTy, &'r GetBlobBuilder<'s>, reqwest::Url, http::request::Request<bytes::Bytes>, StatusCode, GetBlobBuilder<'t0>, &'t1 BlobClient, &'t2 (dyn azure_core::HttpClient + 't3), Pin<Box<(dyn Future<Output = std::result::Result<http::response::Response<bytes::Bytes>, Box<(dyn StdError + Send + Sync + 't4)>>> + Send + 't5)>>, ()}`
    = note: required because it appears within the type `[static generator@GetBlobBuilder<'<empty>>::execute::{closure#0} for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5> {ResumeTy, &'r GetBlobBuilder<'s>, reqwest::Url, http::request::Request<bytes::Bytes>, StatusCode, GetBlobBuilder<'t0>, &'t1 BlobClient, &'t2 (dyn azure_core::HttpClient + 't3), Pin<Box<(dyn Future<Output = std::result::Result<http::response::Response<bytes::Bytes>, Box<(dyn StdError + Send + Sync + 't4)>>> + Send + 't5)>>, ()}]`
    = note: required because it appears within the type `from_generator::GenFuture<[static generator@GetBlobBuilder<'<empty>>::execute::{closure#0} for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5> {ResumeTy, &'r GetBlobBuilder<'s>, reqwest::Url, http::request::Request<bytes::Bytes>, StatusCode, GetBlobBuilder<'t0>, &'t1 BlobClient, &'t2 (dyn azure_core::HttpClient + 't3), Pin<Box<(dyn Future<Output = std::result::Result<http::response::Response<bytes::Bytes>, Box<(dyn StdError + Send + Sync + 't4)>>> + Send + 't5)>>, ()}]>`
    = note: required because it appears within the type `impl Future`
    = note: required because it appears within the type `impl Future`
    = note: required because it appears within the type `for<'r, 's, 't0, 't1, 't2, 't3> {ResumeTy, azure_core::prelude::Range, GetBlobBuilder<'r>, &'s GetBlobBuilder<'t0>, impl Future, ()}`
    = note: required because it appears within the type `[static generator@GetBlobBuilder<'<empty>>::stream::{closure#0}::{closure#0} for<'r, 's, 't0, 't1, 't2, 't3> {ResumeTy, azure_core::prelude::Range, GetBlobBuilder<'r>, &'s GetBlobBuilder<'t0>, impl Future, ()}]`
    = note: required because it appears within the type `from_generator::GenFuture<[static generator@GetBlobBuilder<'<empty>>::stream::{closure#0}::{closure#0} for<'r, 's, 't0, 't1, 't2, 't3> {ResumeTy, azure_core::prelude::Range, GetBlobBuilder<'r>, &'s GetBlobBuilder<'t0>, impl Future, ()}]>`
    = note: required because it appears within the type `impl Future`
    = note: required because it appears within the type `futures_util::unfold_state::UnfoldState<GetBlobBuilder<'a>::stream::States, impl Future>`
    = note: required because it appears within the type `futures_util::stream::unfold::Unfold<GetBlobBuilder<'a>::stream::States, [closure@GetBlobBuilder<'<empty>>::stream::{closure#0}], impl Future>`
    = note: required because it appears within the type `impl Stream`
    = note: required because it appears within the type `tokio_stream::stream_ext::map::Map<impl Stream, [closure@src/provider/mod.rs:313:18: 313:76]>`
    = note: required for the cast to the object type `dyn Stream<Item = std::result::Result<bytes::Bytes, ProviderError>> + Send + Sync + Unpin`

cc @rylev

@thomastaylor312 thomastaylor312 added the bug This issue requires a change to an existing behavior in the product in order to be resolved. label Jan 29, 2021
@tustvold
Copy link

Given consuming a stream requires a mutable reference, I'm not sure what one would gain from a Sync Stream, i.e. &Stream: Send?

@rylev
Copy link
Contributor

rylev commented May 19, 2022

Closing this as I think this issue is no longer relevant. We can reopen if it turns out this isn't true.

@rylev rylev closed this as completed May 19, 2022
@thomastaylor312
Copy link
Author

I am guessing if I go back to the code that caused this with my additional rust experience, I can probably find a way to make it not Sync. If I find a good reason, I'll come back

@github-actions github-actions bot locked and limited conversation to collaborators Feb 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved.
Projects
None yet
Development

No branches or pull requests

3 participants