Ban Management

Ban Management

193k Downloads

Crashing unban task causes to many connections to mysql

Maescool opened this issue ยท 3 comments

commented

Spigot 1.8.3
Banmanager 5.5.0

Multiple spigots use the same bm_local in this setup

[02:49:24] [Craft Scheduler Thread - 2010/WARN]: Exception in thread "Craft Scheduler Thread - 2010"
[02:49:24] [Craft Scheduler Thread - 2010/WARN]: org.apache.commons.lang.UnhandledException: Plugin BanManager v5.5.0 generated an exception while executing task 11
        at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
        at me.confuser.banmanager.data.PlayerBanRecord.equalsBan(PlayerBanRecord.java:62)
        at me.confuser.banmanager.runnables.BanSync.newUnbans(BanSync.java:97)
        at me.confuser.banmanager.runnables.BanSync.run(BanSync.java:38)
        at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftTask.run(CraftTask.java:71)
        at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
        ... 3 more

This happened every minute untill

[02:50:12] [Craft Scheduler Thread - 2019/WARN]: Exception in thread "Craft Scheduler Thread - 2019"
[02:50:12] [Craft Scheduler Thread - 2019/WARN]: org.apache.commons.lang.UnhandledException: Plugin BanManager v5.5.0 generated an exception while executing task 11
        at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Could not get next result for class me.confuser.banmanager.data.PlayerBanData
        at me.confuser.banmanager.internal.ormlite.stmt.SelectIterator.next(SelectIterator.java:183)
        at me.confuser.banmanager.runnables.BanSync.newBans(BanSync.java:53)
        at me.confuser.banmanager.runnables.BanSync.run(BanSync.java:31)
        at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftTask.run(CraftTask.java:71)
        at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
        ... 3 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 10 times. Giving up.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
        at com.mysql.jdbc.Util.getInstance(Util.java:382)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
        at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2239)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2168)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
        at sun.reflect.GeneratedConstructorAccessor36.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:208)
        at me.confuser.banmanager.internal.ormlite.jdbc.JdbcConnectionSource.makeConnection(JdbcConnectionSource.java:252)
        at me.confuser.banmanager.internal.ormlite.jdbc.JdbcPooledConnectionSource.getReadWriteConnection(JdbcPooledConnectionSource.java:136)
        at me.confuser.banmanager.internal.ormlite.jdbc.JdbcPooledConnectionSource.getReadOnlyConnection(JdbcPooledConnectionSource.java:111)
        at me.confuser.banmanager.internal.ormlite.field.FieldType.assignField(FieldType.java:555)
        at me.confuser.banmanager.internal.ormlite.stmt.mapped.BaseMappedQuery.mapRow(BaseMappedQuery.java:71)
        at me.confuser.banmanager.internal.ormlite.stmt.SelectIterator.getCurrent(SelectIterator.java:270)
        at me.confuser.banmanager.internal.ormlite.stmt.SelectIterator.nextThrow(SelectIterator.java:161)
        at me.confuser.banmanager.internal.ormlite.stmt.SelectIterator.next(SelectIterator.java:173)
        ... 7 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
        at com.mysql.jdbc.Util.getInstance(Util.java:382)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:931)
        at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4031)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1296)
        at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2338)
        at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2186)
        ... 26 more

To my understanding, the auto unban task, crashes for some reason.. but doesn't cleanup propperly after crash.
so it keeps it connection open to mysql, but it re-opens a new connection every time it runs the task again (had a couple of hundred connections open from this server to my mysql.. which is limited to 1000)

So next to fixing the null pointer to the unban problem, I'm also requesting that every exception catch also makes sure the crash cleans up stuff.. like extra mysql connections..

commented

Tip: If java7 is used a try-with resources could be implemented (try to put the task inside a 'closable' object).

commented

You shouldn't be getting an NPE. Sounds like a data integrity issue.

I've already changed the sync tasks to ensure the resources are closed on caught exceptions, I just need to commit it.

commented

I met error when unban a player
(Banmanager v5.6.0)
[03:50:43] [Craft Scheduler Thread - 7/WARN]: org.apache.commons.lang.UnhandledException: Plugin BanManager v5.6.0 generated an exception while executing task 104
at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at me.confuser.banmanager.commands.UnbanCommand$1.run(UnbanCommand.java:88)
at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftTask.run(CraftTask.java:71)
at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
... 3 more