r3labs / sse

Server Sent Events server and client for Golang
Mozilla Public License 2.0
857 stars 179 forks source link

SSE client randomly dies #141

Closed fleaz closed 1 year ago

fleaz commented 1 year ago

Hey,

thanks for this library. I used it recently to build codemonauts/wikiwatch which is basically working fine but sometimes the client just dies and exits.

My stripped down main function looks like this

    client := sse.NewClient("https://stream.wikimedia.org/v2/stream/recentchange")

    err = client.Subscribe("recentchange", func(msg *sse.Event) {
        handleRecentChange(msg, config)
    })
    if err != nil {
        log.Error(err)
    }

    client.OnDisconnect(func(c *sse.Client) {
        log.Error("Disconnected!")
    })

    log.Error("Done")

This works for around 5-10 minutes (correctly processing all incoming events in that time, and then I get "Done" and the programm terminates. So I assume this is not a disconnect because the OnDisconnect function is not called, but also there is no error from Subscribe either.

How can I find out what's the cause of this?

purehyperbole commented 1 year ago

Hey @fleaz thanks for raising the issue.

Looking at your example, OnDiscconnect won't be set up, as Subscribe is a blocking call. I would suggest setting up your OnDisconnect handler before subscribing and see if that returns anything useful.

fleaz commented 1 year ago

Sorry for the late reply.

I moved the OnDisconnect handler to the top like you recommended and now the code is running fine since weeks (but still didn't print out anything 🙃)

I'm a bit confused, but as long as it works without problems, I won't question it further and will close this for now.

Thanks :)