Bug #12596 | wrong behavior if connection timeout reached | ||
---|---|---|---|
Submitted: | 16 Aug 2005 10:08 | Modified: | 16 Aug 2005 12:52 |
Reporter: | Riccardo Cohen | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / J | Severity: | S2 (Serious) |
Version: | 4.1.12 | OS: | Windows (windows+linux) |
Assigned to: | CPU Architecture: | Any |
[16 Aug 2005 10:08]
Riccardo Cohen
[16 Aug 2005 12:32]
Mark Matthews
The JDBC specification explicitly forbids isClosed() returning whether the connection is "valid" or not. The _only_ thing isClosed() does is tell the caller whether close() has been called on the connection. JDBC-4.0 looks to have an isValid() method. isClosed() can _not_ be implemented the way in which you've implemented it, because that "SELECT " may _never_ return based on how the network has failed (if it has failed). This violates the contract that JDBC clients expect, because isClosed() is documented in general to not be a blocking method. In general, it doesn't make a lot of sense to let a JDBC connection sit idle long enough for wait_timeout to expire (it means you are wasting both server and client-side resources). Therefore you should configure things in your application to not do so.
[16 Aug 2005 12:44]
Riccardo Cohen
Thanks for the quick answer. Actually the connection is in my connection pool, and should stay connected (if not what's the use of a connection pool :) ) I thought that IsClosed() would tell me if it is still connected (for timeout pb, network pb or else) Could you tell me if there is a function for that ? Thanks
[16 Aug 2005 12:52]
Mark Matthews
There is currently no method available to check whether a connection is valid or not. (The previous comment said it is being planned for JDBC-4.0). At least with MySQL, the reason for a connection pool is to _limit_ the ultimate number of connections that are created. Since it only takes a few milliseconds to open a connection to MySQL, there is not a compelling reason in most cases to hold connections idle for more than a few minutes, and certainly not as long as wait_timeout which by default is 8 hours.
[16 Aug 2005 13:38]
Riccardo Cohen
Thanks a lot