Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Added check for negative nanosTimeout after connection acquisition. I… #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

xgp
Copy link

@xgp xgp commented Jun 20, 2016

Added check for negative nanosTimeout after connection acquisition. In a case where a connection takes a long time to establish, this prevents a call to mysql sleep() with a negative number, which will yield: java.sql.SQLException: Incorrect arguments to sleep.

See: #3

…n a case where a connection takes a long time to establish, this prevents a call to mysql sleep() with a negative number, which will yield: java.sql.SQLException: Incorrect arguments to sleep.
@@ -89,6 +89,10 @@ protected boolean awaitNanosInternal(long nanosTimeout) throws InterruptedExcept

// Adjust nanosTimeout (due to time it took to get a connection)
nanosTimeout -= (System.nanoTime() - now);
if (nanosTimeout <= 0) {
LOG.trace("After connection acquired, timeout was negative or zero: {}", nanosTimeout);
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think we need the LOG.trace

@bramp
Copy link
Owner

bramp commented Jun 21, 2016

This was a good catch, but on closer inspection I wonder if there is still an issue. If Math.round(nanosTimeout / 1000000.0) rounds to zero, then we will sleep for 0 milliseconds. Perhaps do the check if <= 0 after the rounding?

@xgp
Copy link
Author

xgp commented Jun 21, 2016

Yep. Done.

LOG.trace("After connection acquired, timeout was negative or zero: {}", nanosTimeout);
float timeout = Math.round(nanosTimeout / 1000000.0) / 1000f;
if (timeout <= 0) {
LOG.trace("After connection acquired, timeout was negative or zero: {}", timeout);
Copy link
Owner

Choose a reason for hiding this comment

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

No need for the LOG.trace

@bramp
Copy link
Owner

bramp commented Jun 21, 2016

Thanks for the changes. Sorry two additional minor comments.

@bramp
Copy link
Owner

bramp commented Nov 2, 2016

Hey xgp, sorry but your changes is now nearly all formatting changes, which makes it hard to know what you changed. Would you undo the formatting changes so we can review just your changes.

Afterwards we can define a format and apply it to the project. I've had some success with "formatter-maven-plugin" to ensure a style is stuck to.

@xgp
Copy link
Author

xgp commented Nov 2, 2016

Sure. I'll do that in the next few days.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants