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

Fixed bug in max reconnection delay initialization. #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rgorodischer
Copy link

This change fixes the following bug in max reconnect delay initialization:

The 'maxDelay' parameter is used to be set in seconds (but if it was specified in milliseconds, the things would be even worser). Currently, it's transformed during initialization with TimeUnit.SECONDS.toMillis.
It means that the specified value is multiplied by 1000 in constructor.
And then it appears in this code snippet from method 'queueReconnect':

long delay = (long) Math.min(maxDelay, Math.pow(2,
node.getReconnectCount())) * 1000;
long reconnectTime = System.currentTimeMillis() + delay;

As you can see, it's multiplied by 1000 second time here, what is obviously causes 1000 times longer delay then the user expects.

@@ -159,7 +159,7 @@ MemcachedNode createMemcachedNode(SocketAddress sa, SocketChannel c,
HashAlgorithm getHashAlg();

/**
* Maximum number of milliseconds to wait between reconnect attempts.
* Maximum number of seconds to wait between reconnect attempts.
Copy link

@jhbae jhbae Feb 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be milliseconds.

Because, in this commit, you just used f.getMaxReconnectDelay()
and as you may already know maxDelay is applied to calculate delay as follows.

long delay = (long) Math.min(maxDelay, Math.pow(2, node.getReconnectCount()) * 1000); long reconnectTime = System.currentTimeMillis() + delay;

As we can see above, delay will be just added to currentTimeMillis()
and the value 1000 is multiplied only to Math.pow(2, node.getReconnectCount()) not to maxDelay.

So I think it should be milliseconds as originally it was.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although maxDelay is in millisecond, maxDelay = TimeUnit.SECONDS.toMillis(f.getMaxReconnectDelay()); MaxReconnectDelay should be in second

Copy link

@caoziwen caoziwen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be in second

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.

3 participants