bramp / db-patterns

Some simple DB patterns implemented onto of MySQL
BSD 2-Clause "Simplified" License
3 stars 1 forks source link

Intermittent java.sql.SQLException: Incorrect arguments to sleep. #3

Open xgp opened 8 years ago

xgp commented 8 years ago

I get the following exception intermittently when using the MySQLBasedQueue. I'm running MySQL 5.7.12 Community Server on Ubuntu.

I'm guessing this has something to do with the lines

nanosTimeout -= (System.nanoTime() - now);

and

s.setFloat(1, Math.round(nanosTimeout / 1000000.0) / 1000f);

which could sometimes yield a negative number, given how the JVM calculates these.

java.lang.RuntimeException: java.sql.SQLException: Incorrect arguments to sleep.
                            at net.bramp.db_patterns.locks.MySQLSleepBasedCondition.awaitNanosInternal(MySQLSleepBasedCondition.java:113)
                            at net.bramp.db_patterns.locks.MySQLSleepBasedCondition.awaitUntil(MySQLSleepBasedCondition.java:149)
                            at net.bramp.db_patterns.queues.MySQLBasedQueue.poll(MySQLBasedQueue.java:243)
Caused by: java.sql.SQLException: Incorrect arguments to sleep.
       at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
       at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
       at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:2090)
       at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1964)
       at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:3306)
       at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:463)
       at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3040)
       at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2288)
       at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2681)
       at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)
       at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
       at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1192)
       at net.bramp.db_patterns.locks.MySQLSleepBasedCondition.awaitNanosInternal(MySQLSleepBasedCondition.java:96)
       ... 7 common frames omitted
xgp commented 8 years ago

I'm testing adding a second negative check at line 92, and I haven't seen the problem resurface.

if (nanosTimeout <= 0) return false;
bramp commented 8 years ago

Ah yes, I think you found a bug :) Pull requests welcome.