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

Footgun in gloo-net's EventSource #495

Open
allsey87 opened this issue Nov 20, 2024 · 0 comments
Open

Footgun in gloo-net's EventSource #495

allsey87 opened this issue Nov 20, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@allsey87
Copy link

allsey87 commented Nov 20, 2024

I spent a good part of today debugging something that I think I would describe as a bit of footgun. To get straight to the point, consider the following code:

fn stream(
    mut self
) -> LocalBoxStream<'static, Result<(String, Option<String>), EventSourceError>> {
     self.event_source.subscribe("put").unwrap()
        .map_ok(|(event_type, message)| (event_type, message.data().as_string()))
        .boxed_local()
}

In this code, self.event_source is a gloo_net::eventsource::futures::EventSource, however the returned stream just returns a ConnectionError when it is pulled. I didn't fully get to the bottom of this, however, it seems that self.event_source is dropped after this function returns, which is either disconnecting the event handlers or closing the connection.

I am sure that my sloppiness is partly to blame here, however, I am used to Rust preventing these sorts of footguns. Is there anything that can be done to improve this?

@allsey87 allsey87 added the bug Something isn't working label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant