Skip to content

Conversation

paulocsanz
Copy link

@paulocsanz paulocsanz commented Jun 6, 2025

This adds a exponential backoff for reconnects when the server closes connections right after they are opened, as currently there is only a backoff when the connection doesn't open at all.

We just had an incident because of this, something thrashed the database, making new ws connections close right after they opened since they couldn't access auth/initial doc data. But since the connection was technically opened for a brief moment it resets the unsucessfull connections exponential backoff. Making it try to reconnect immediately, indefinitely, causing even more strain on our database that was already struggling. Spreading to more and more users.

The only caveat is that we only reset this backoff if a connection lives for at least maxBackoffIntervalOnSuccessfulConnects * 2 ms, since the default is 2500ms seems pretty reasonable.

We could also default maxBackoffIntervalOnSuccessfulConnects to 0 to ensure current behavior is not altered, but it seems that everybody would benefit from this being on by default.

paulocsanz and others added 2 commits June 6, 2025 19:33
…ere opened

This adds a exponential backoff for reconnects when the server closes the connections too fast, as opposed to only having it when the connection doesn't open at all.

We just had an incident because of this, something thrashed the database, making new ws connections close right after they opened since they couldn't access auth/initial doc data. But since the connection was technically opened for a brief moment it resets the unsucessfull connections exponential backoff. Making it try to reconnect immediately, indefinitely, causing even more strain on our database that was already struggling. Spreading to more and more users.

The only caveat is that we only reset this backoff if a connection lives for at least `maxBackoffIntervalOnSuccessfulConnects * 2` ms, since the default is 2500ms seems pretty reasonable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant