Avoid spamming server if it's closing connections right after they were opened#195
Open
paulocsanz wants to merge 2 commits intoyjs:masterfrom
Open
Avoid spamming server if it's closing connections right after they were opened#195paulocsanz wants to merge 2 commits intoyjs:masterfrom
paulocsanz wants to merge 2 commits intoyjs:masterfrom
Conversation
…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.
Author
|
Hi @dmonad could I get a review on this? It fixes a issue that took our platform down (railway.com), I would love to stop forking this repo! And I'm sure other users will benefit from it! |
Author
|
Happy to make changes if you see fit, I understand it's not the best variable naming, but wanted to be specific on it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 * 2ms, since the default is 2500ms seems pretty reasonable.We could also default
maxBackoffIntervalOnSuccessfulConnectsto 0 to ensure current behavior is not altered, but it seems that everybody would benefit from this being on by default.