Skip to content
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

fix sleep only on repeat of server list during reconnect #744

Merged
merged 1 commit into from
Feb 16, 2023

Conversation

scottf
Copy link
Collaborator

@scottf scottf commented Feb 16, 2023

This code in connection does the reconnect delayon every round except the very first because srvPool.First() is always the first thing in the pool and srvPool.SelectNextServer does not advance the pool, so line 7 is always true. (Lines 10 and 16 were added to demonstrate, not part of original code.)

01: Srv cur;
02: int wlf = 0;
03: bool doSleep = false;
04: while ((cur = srvPool.SelectNextServer(Opts.MaxReconnect)) != null)
05: {
06:     // check if we've been through the list
07:     if (cur == srvPool.First())
08:     {
09:         doSleep = (wlf != 0);
10:         Console.WriteLine("== wlf: " + wlf + ", doSleep: " + doSleep + ", cur: " + cur.Url + " == " + srvProvider.First().Url);
11:         wlf++;
12:     }
13:     else
14:     {
15:         doSleep = false;
16:         Console.WriteLine("!= wlf: " + wlf + ", doSleep: " + doSleep + ", cur: " + cur.Url + " != " + srvProvider.First().Url);
17:     }

The output is this.

== wlf: 0, doSleep: False, cur: nats://localhost:11498/ == nats://localhost:11498/
== wlf: 1, doSleep: True, cur: nats://localhost:11497/ == nats://localhost:11497/
== wlf: 2, doSleep: True, cur: nats://localhost:11498/ == nats://localhost:11498/
== wlf: 3, doSleep: True, cur: nats://localhost:11497/ == nats://localhost:11497/
== wlf: 4, doSleep: True, cur: nats://localhost:11498/ == nats://localhost:11498/
== wlf: 5, doSleep: True, cur: nats://localhost:11497/ == nats://localhost:11497/
== wlf: 6, doSleep: True, cur: nats://localhost:11498/ == nats://localhost:11498/
== wlf: 7, doSleep: True, cur: nats://localhost:11497/ == nats://localhost:11497/

@scottf scottf merged commit 1207845 into master Feb 16, 2023
@scottf scottf deleted the pool-first-fix branch February 16, 2023 17:00
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.

None yet

3 participants