Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

MySQL error 1040 “Too many connections” #59

Open
Akiranya opened this issue Jul 12, 2019 · 0 comments
Open

MySQL error 1040 “Too many connections” #59

Akiranya opened this issue Jul 12, 2019 · 0 comments

Comments

@Akiranya
Copy link

Akiranya commented Jul 12, 2019

问题

每次使用 /heh view 浏览商城时,会新建一个 mysql 的 connection,之后该 connection 会一只处于 sleep 的状态,不会自行 kill 掉,从而占用 mysql 的可用连接池。一旦 connections 超过了 max_connections/heh view 就无法再使用。该问题还导致其他使用 mysql 的功能/程序不能正常运行,例如 heh的木牌商店,CoreProtect 等需要用到 mysql 的插件

如何确认以上问题

  1. 设置 heh 使用 mysql
  2. 打开 mysql 的命令行
  3. 每当使用 /heh view 后,命令行里输入 show processlist; 会看见有一个新的 connection 出现,而且很长时间内不会自动关闭

Bug reproduction steps

不断重复 /heh view 操作,从而新建 connections。直到 connections 超过 mysql 的 max_connections,那么后台就会出现如下提示:

[23:38:50 INFO]: Nailm issued server command: /heh view
[23:38:50 WARN]: java.lang.RuntimeException: connection failed: root@jdbc:MySQL://localhost:3306/heh?useSSL=false&verifyServerCertificate=false
[23:38:50 WARN]: 	at cat.nyaa.nyaacore.database.provider.MysqlDatabase.createConnection(MysqlDatabase.java:51)
[23:38:50 WARN]: 	at cat.nyaa.nyaacore.database.relational.BaseDatabase.newConnection(BaseDatabase.java:48)
[23:38:50 WARN]: 	at cat.nyaa.nyaacore.database.provider.MysqlDatabase.queryTransactional(MysqlDatabase.java:86)
[23:38:50 WARN]: 	at cat.nyaa.nyaacore.database.provider.MysqlDatabase.queryTransactional(MysqlDatabase.java:15)
[23:38:50 WARN]: 	at cat.nyaa.HamsterEcoHelper.database.Database.getMarketItems(Database.java:106)
[23:38:50 WARN]: 	at cat.nyaa.HamsterEcoHelper.market.MarketGUI.openGUI(MarketGUI.java:77)
[23:38:50 WARN]: 	at cat.nyaa.HamsterEcoHelper.market.MarketManager.openGUI(MarketManager.java:106)
[23:38:50 WARN]: 	at cat.nyaa.HamsterEcoHelper.market.MarketCommands.view(MarketCommands.java:63)
[23:38:50 WARN]: 	at jdk.internal.reflect.GeneratedMethodAccessor20.invoke(Unknown Source)
[23:38:50 WARN]: 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[23:38:50 WARN]: 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[23:38:50 WARN]: 	at cat.nyaa.nyaacore.CommandReceiver.acceptCommand(CommandReceiver.java:207)
[23:38:50 WARN]: 	at cat.nyaa.nyaacore.CommandReceiver.acceptCommand(CommandReceiver.java:205)
[23:38:50 WARN]: 	at cat.nyaa.nyaacore.CommandReceiver.onCommand(CommandReceiver.java:180)
[23:38:50 WARN]: 	at cat.nyaa.HamsterEcoHelper.CommandHandler.onCommand(CommandHandler.java:63)
[23:38:50 WARN]: 	at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45)
[23:38:50 WARN]: 	at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159)
[23:38:50 WARN]: 	at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:739)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.PlayerConnection.handleCommand(PlayerConnection.java:1831)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.PlayerConnection.a(PlayerConnection.java:1639)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:47)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:5)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:18)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.TickTask.run(SourceFile:18)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:127)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:105)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.MinecraftServer.aW(MinecraftServer.java:1002)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.MinecraftServer.executeNext(MinecraftServer.java:995)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:115)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.MinecraftServer.sleepForTick(MinecraftServer.java:979)
[23:38:50 WARN]: 	at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:912)
[23:38:50 WARN]: 	at java.base/java.lang.Thread.run(Thread.java:834)
[23:38:50 WARN]: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"
[23:38:50 WARN]: 	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[23:38:50 WARN]: 	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[23:38:50 WARN]: 	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[23:38:50 WARN]: 	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
[23:38:50 WARN]: 	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
[23:38:50 WARN]: 	at com.mysql.jdbc.Util.getInstance(Util.java:408)
[23:38:50 WARN]: 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
[23:38:50 WARN]: 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
[23:38:50 WARN]: 	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
[23:38:50 WARN]: 	at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1038)
[23:38:50 WARN]: 	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2199)
[23:38:50 WARN]: 	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2230)
[23:38:50 WARN]: 	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2025)
[23:38:50 WARN]: 	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:778)
[23:38:50 WARN]: 	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
[23:38:50 WARN]: 	at jdk.internal.reflect.GeneratedConstructorAccessor75.newInstance(Unknown Source)
[23:38:50 WARN]: 	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[23:38:50 WARN]: 	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
[23:38:50 WARN]: 	at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
[23:38:50 WARN]: 	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
[23:38:50 WARN]: 	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
[23:38:50 WARN]: 	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
[23:38:50 WARN]: 	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
[23:38:50 WARN]: 	at cat.nyaa.nyaacore.database.provider.MysqlDatabase.createConnection(MysqlDatabase.java:48)
[23:38:50 WARN]: 	... 32 more

游戏内会提示
image

mysql 命令行执行 show processlist; 的结果:
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant