Skip to content

Footgun in gloo-net's EventSource #495

Open
@allsey87

Description

@allsey87

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions