[CONJ-1] Timeout exceptions when using Apache DBCP properties Created: 2012-12-07  Updated: 2013-01-04  Resolved: 2012-12-16

Status: Closed
Project: MariaDB Connector/J
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Rasmus Johansson (Inactive) Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 0
Labels: None


 Description   

When using validation-query and validation-query-timeout for them ("SELECT 1" and a timeout of 3), timeout exceptions occur in all queries. If the validation-query-timeout parameter (and only that one) is removed, everything works as expected.

These are Apache DBCP properties.



 Comments   
Comment by Rasmus Johansson (Inactive) [ 2012-12-07 ]

Reaching out to user that experienced this to get more information.

Comment by Vladislav Vaintroub [ 2012-12-09 ]

I tried a lot of things (without DBCP, since I do not have any knowlegde about it), and could not see any difference in how setQueryTimeout/getQuerytimeout behave between ConnectorJ and MariaDB JDBC.

I guess we need a runnable self-contained repro, be it DBCP or anything else.

Comment by Vladislav Vaintroub [ 2012-12-16 ]

I think I fixed it now. I did not try DBCP, but playing around with timeouts revealed JVM bug in socket timeouts that were used for query timeout. So this got reimplemented again with java.util.Timer.

Comment by George El Boustani [ 2013-01-04 ]

This fix solved the timeout exceptions, however it creates a resource leak as the Timer is not being cancelled and nulled. See attached patch

Comment by George El Boustani [ 2013-01-04 ]

Patch:

=== modified file 'src/main/java/org/mariadb/jdbc/MySQLStatement.java'
--- src/main/java/org/mariadb/jdbc/MySQLStatement.java	2012-12-25 15:38:29 +0000
+++ src/main/java/org/mariadb/jdbc/MySQLStatement.java	2013-01-04 01:26:09 +0000
@@ -373,6 +373,9 @@
                 }
             }
         }
+
+        cancelTimer();
+
         isClosed = true;
     }
 
@@ -498,6 +501,8 @@
     public void cancel() throws SQLException {
         try {
             protocol.cancelCurrentQuery();
+
+            cancelTimer();
         } catch (QueryException e) {
             SQLExceptionMapper.throwException(e, connection, this);
 
@@ -1182,4 +1187,11 @@
 		// TODO Auto-generated method stub
 		return false;
 	}
+
+    private void cancelTimer() {
+        if (timer != null) {
+            timer.cancel();
+            timer = null;
+        }
+    }
 }

Comment by George El Boustani [ 2013-01-04 ]

Before the patch over 3000 threads were running, and after it was down to 80

Comment by Vladislav Vaintroub [ 2013-01-04 ]

thanks. Would it be possible for you to paste a test case for "3000 threads are running"?

Comment by Vladislav Vaintroub [ 2013-01-04 ]

After reading docs for java.util.Timer - yes, you're right that there are excessive threads when using multiple timers. So ,the way to fix is it, is to use single (per-JVM) timer with multiple timerTasks , which I done in this patch :
http://bazaar.launchpad.net/~maria-captains/mariadb-java-client/trunk/revision/376

Generated at Thu Feb 08 03:12:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.