-
-
Notifications
You must be signed in to change notification settings - Fork 1
Added check for negative nanosTimeout after connection acquisition. I… #4
base: master
Are you sure you want to change the base?
Conversation
…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); |
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 don't think we need the LOG.trace
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? |
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); |
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.
No need for the LOG.trace
Thanks for the changes. Sorry two additional minor comments. |
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. |
Sure. I'll do that in the next few days. |
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