wryk / tusky-api

0 stars 1 forks source link

Infinite reconnects #2

Open Vavassor opened 7 years ago

Vavassor commented 7 years ago

I find a lot of sessions hit errors and then just try to reconnect and get the same error over and over. The most common in the logs are (listed with HTTP status codes):

This overloaded the server I have running for Tusky 1.1.4-beta.1, so it's a LOT of reconnects.

3xx-level status codes return a Location in their header to use as the redirect. So it could just be used to save that as a "current redirect URL" and keep a count to keep following until some redirect limit. Or there's probably a package out there that implements follow-redirects for WebSocket, I'm not sure.

For unresolved errors, I'm not sure what the best re-connection scheme is. A reconnect limit is easiest to implement. But it also means if the instance comes back online later after the client has given up, then they just don't receive notifications until Tusky is restarted, which is kind of weak. I guess you could just do longer and longer reconnect timeouts. Or some kind of background periodic checking of dead connections, to see if they came back online?

wryk commented 7 years ago

Looks like websockets/ws#812 doesn't follow redirect. I have replaced ws by uws (https://github.com/uNetworking/uWebSockets) this morning for performance reason but I don't think it'll will fix this issue. A simple limit counter could be fine for now until I find a more reliable way to reconnect and expire connections.

I'll give another try to the SSE streaming API, it's not the best SSE implementation but I think I can use it with EventSource/eventsource (https://github.com/EventSource/eventsource) custom headers feature

wryk commented 7 years ago

I pushed some commits with testing tools and I catched your 301 redirect on mamot.fr with WebSocket on unexpected-response event. I think i can add a follow-redirect with that.

And the SSE listener works fine, automatically followed redirect on mamot.fr (but got a 401, i don't have an account :P)