-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat: reconnect immediately on first retry #338
Conversation
@im-adithya please re-read the issue and think through it. If you don't understand it, please do ask before writing code |
89e91c4
to
8de476a
Compare
@rolznz can you re-review? |
service/start.go
Outdated
@@ -63,6 +64,8 @@ func (svc *service) startNostr(ctx context.Context, encryptionKey string) error | |||
if contextCancelled { | |||
break | |||
} | |||
} else if i > 0 { |
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 this if-else with checking the i
value makes things over-complicated. I don't think we need to check the iteration at all now since we now control whether we back off or not.
service/start.go
Outdated
@@ -46,10 +46,11 @@ func (svc *service) startNostr(ctx context.Context, encryptionKey string) error | |||
defer svc.wg.Done() | |||
//Start infinite loop which will be only broken by canceling ctx (SIGINT) | |||
var relay *nostr.Relay | |||
immediateRetry := false |
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 it'd be easier to understand to flip this and call it waitToReconnectSeconds
, and use a number instead of a boolean, so that later we are able to easily adjust the algorithm (e.g. do an exponential back off algorithm)
service/start.go
Outdated
|
||
for i := 0; ; i++ { | ||
// wait for a delay before retrying except on first iteration | ||
if i > 0 { | ||
if i > 0 && !immediateRetry { |
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 would remove the iteration check here and do if waitToReconnectSeconds > 0
@im-adithya can you address the feedback? |
Ready now @rolznz! |
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.
tACK
Fixes #297
Is this what we want here @rolznz?