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

Calling Reflector::poll in separate thread/task #97

Closed
milesgranger opened this issue Dec 3, 2019 · 5 comments
Closed

Calling Reflector::poll in separate thread/task #97

milesgranger opened this issue Dec 3, 2019 · 5 comments
Labels
bug Something isn't working help wanted Not immediately prioritised, please help!

Comments

@milesgranger
Copy link

milesgranger commented Dec 3, 2019

Good day sir!

Regarding version 0.22.1

I'm trying to do as advised, calling .poll() in a separate task

tokio::spawn(async move {
    loop {
        let _ = reflector.poll().await.unwrap();
    }
});

Results in:

tokio::spawn(async move {
    |     ^^^^^^^^^^^^ `dyn futures_core::stream::Stream<Item = std::result::Result<kube::api::resource::WatchEvent<kube::api::resource::Object<crd::gordo::gordo::GordoSpec, crd::gordo::gordo::GordoStatus>>, kube::Error>>` cannot be sent between threads safely

This will work however in 0.20.0

I've attempted wrapping the reflector, (naively) in Arc<RwLock<Reflector<Gordo>> to no avail.

I really appreciate all your examples, but couldn't find any which actually put this into a different task, aside from controller-rs but that's on version 0.18 in which case this will work.

When you have the time, could you give me a pointer?

@clux
Copy link
Member

clux commented Dec 3, 2019

Ah what!? The Stream isn't Send 😱

That's definitely awkward. Kind of rushed out that release because all the examples work and delayed the threaded examples because actix is in a weird pre-2.0.0 state right now.

Definitely need to make some changes to make the threaded case work here ASAP. Thanks for the issue. Will start a branch and try things. Help from anyone else who are good at the type puzzle would also be appreciated :-) (cc @kitfre)

clux added a commit that referenced this issue Dec 3, 2019
@clux clux added bug Something isn't working help wanted Not immediately prioritised, please help! labels Dec 3, 2019
@clux
Copy link
Member

clux commented Dec 3, 2019

Think we might need to change the internal client watch call to return a BoxStream, because the stream isn't even exposed to a Reflector and types still complain 🤔

@clux
Copy link
Member

clux commented Dec 4, 2019

Released the fix in 0.22.2. Thanks for the report and thanks once again @kitfre 👏

@clux
Copy link
Member

clux commented Dec 4, 2019

Most reflector examples have been updated, you should not need to wrap anything in Arc because Reflector and Informer implement Clone and maintain Arcs under the hood.

@milesgranger
Copy link
Author

Most excellent, thank you so much! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Not immediately prioritised, please help!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants