New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms. #1132
Comments
Enable the |
Okay I’ll enable that. I changed my code around completely and now I seem to only be getting primary key duplicate error. |
What should I use for that leakDetectionThreshold? Also here's the duplicated entry error: |
Two things... One, try 30 seconds (30000ms) for the leakDetectionThreshold. Two, duplicate key errors have nothing to do with the pool, but represent an application bug. If it was working on another pool, it is likely due to a “lucky” side-effect, such as commit-on-close behavior. You’re on your own chasing that one down. |
Okay I'll try that out |
Fixed it. Thanks. |
Okay looks like the leakDetectionThreshold picked this https://hastebin.com/gasiyifota.vbs I also provided my code and line number |
Not sure what caused that but it hasn't happened since. |
@ItzVinex Looking at the code, the following pattern will leak a connection: try {
conn = hikari.getConnection(); <-- Possible leak. If an exception is thrown, the Connection is never closed.
sql = conn.prepareStatement(...);
...
conn = hikari.getConnection(); <-- Leak. Previous Connection referenced by conn is overwritten and never closed.
sql = conn.prepareStatement(...);
} catch (SQLException e) {
...
} finally {
} First, you do not need two Connections here. Second, use Java's try-with-resources to handle closing Connections and Statements. Better: try (Connection conn = hikari.getConnection();
PreparedStatement sql1 = conn.prepareStatement(...);
PreparedStatement sql2 = conn.prepareStatement(...)) {
sql1.setXXX(...);
...
sql1.executeUpdate();
// No need to close 'conn', 'sql1' or 'sql2' explicitly. The try guarantees they will be closed.
}
catch (SQLException e) {
...
} |
`public void newDatabaseEntry(Player p) {
Updated the code. So you're saying I don't need to close them at all? |
Worked perfectly! Wow I never new you could do that with try-and-catches. |
Take that back it ended up giving me this error. https://hastebin.com/owexebaxag.vbs Provided code and line number within the log. |
I also converted my SQLManager class to your try-with-resource statement suggestion and this happen. CODE and ERROR as well as LINE NUMBER included. |
All fixed, but if you can explain why you can't use RS in the resource. |
Line 81 is executing the query before you have set the query parameters on line 82. ResultSets are automatically closed when the Statement is closed, so don’t worry about it. |
Ok I appreciate it. Thanks! |
Environment
Have you searched the CLOSED issues already? How about checking stackoverflow?
Yes.
I have two errors which are the same but in different classes.
https://hastebin.com/banobifipe.md
LINE 744:
ps2 = getHikari().getConnection().prepareStatement( "UPDATE
PlayersSET
1v1Rating=?,
2v2Rating=?,
FFARating=?,
FFAKills=?,
FFADeaths=?,
Coins=?,
Spins=?,
Skeleton=?,
Creeper=?,
Zombie=?,
Enderman=?,
Herobrine=?,
Dreadlord=?,
Arcanist=?,
Shaman=?,
Golem=?,
Pigman=?,
Blaze=?,
Spider=?,
Block=?,
VanityArmor=?,
Trail=?,
PlayerName=? WHERE
UUID=?");
LINE 153:
PreparedStatement sql2 = Corrupted.getInstance().getHikari().getConnection().prepareStatement("SELECT * FROM
Players");
My configuration:
hikari = new HikariDataSource(); hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); hikari.setMaximumPoolSize(10); hikari.addDataSourceProperty("serverName", "localhost"); hikari.addDataSourceProperty("port", "3306"); hikari.addDataSourceProperty("databaseName", "DB"); hikari.addDataSourceProperty("user", "username"); hikari.addDataSourceProperty("password", "mypass");
If this helps I have another program using the same database with HikariCP and works perfectly fine.
The text was updated successfully, but these errors were encountered: