-
Couldn't load subscription status.
- Fork 4
Add configurable backoff #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LostKobrakai
wants to merge
2
commits into
main
Choose a base branch
from
chore/configurable-backoff
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| defmodule Sink.Connection.Client.Backoff do | ||
| @moduledoc """ | ||
| A behaviour for implementing client backoff on consecutive unsuccessful connection attempts. | ||
| """ | ||
|
|
||
| @typedoc "Number of consecutive connection attempts having been unsuccessful before" | ||
| @type attempts :: pos_integer() | ||
|
|
||
| @typedoc "True if the last connection attempt received a connection request rejection" | ||
| @type connection_request_rejected :: boolean() | ||
|
|
||
| @typedoc "Backoff duration in milliseconds" | ||
| @type backoff :: non_neg_integer() | ||
|
|
||
| @doc """ | ||
| Calculate the backoff to apply. | ||
| """ | ||
| @callback backoff_duration(attempts, connection_request_rejected) :: backoff | ||
|
|
||
| @doc false | ||
| def add_jitter(interval) do | ||
| variance = div(interval, 10) | ||
| interval + Enum.random(-variance..variance) | ||
| end | ||
| end |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| defmodule Sink.Connection.Client.DefaultBackoff do | ||
| @behaviour Sink.Connection.Client.Backoff | ||
|
|
||
| # Always backoff 5 minutes when the server actively denied a connection | ||
| def backoff_duration(_, true), do: :timer.minutes(5) | ||
|
|
||
| # Backoff in growing steps for other issues in connecting | ||
| def backoff_duration(1, false), do: 50 | ||
| def backoff_duration(2, false), do: :timer.seconds(1) | ||
| def backoff_duration(3, false), do: :timer.seconds(5) | ||
| def backoff_duration(4, false), do: :timer.seconds(30) | ||
| def backoff_duration(_, false), do: :timer.seconds(60) | ||
| end |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to think about this the other way: if the connection was closed when the connection state was
:requesting_connectionthen we have a pretty good guess (though this is still a bit of a hack) that the server rejected the connection.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that's a reasonable assumption to make. It could just as much be caused by a network or application issue while sink is in that state. Getting a negative connection response should be the reason for sink to consider itself being rejected. Any negative connection response will result in
State.disconnecting?(state)being true.I don't think penalizing a nova on bad network with a 5 minutes timeout would be a good idea and we should rather expect that connection responses are actually received if the nova is not already having a hard time keeping the connection open.