简体   繁体   English

Netty Server接受连接但不执行任何操作

[英]Netty Server accept connection and do nothing

I didnt trace-out the reason for this bug "My netty Server didnt proceess any message after the following exception." 我没有找出此错误的原因“在发生以下异常后,我的Netty Server没有处理任何消息。”

  org.jboss.netty.channel.SimpleChannelHandler - EXCEPTION, please implement com.kakapo.unity.handler.RegistrationHandler.exceptionCaught() for proper handling.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 223,384,284 milliseconds ago.  The last packet sent successfully to the server was 223,384,284 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
    at sun.reflect.GeneratedConstructorAccessor13.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3364)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1983)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)
    at snaq.db.CachedPreparedStatement.executeQuery(CachedPreparedStatement.java:81)
    at com.kakapo.unity.handler.CustomIPFilterHandler.accept(CustomIPFilterHandler.java:46)
    at org.jboss.netty.handler.ipfilter.IpFilteringHandlerImpl.handleUpstream(IpFilteringHandlerImpl.java:118)
    at org.jboss.netty.handler.logging.LoggingHandler.handleUpstream(LoggingHandler.java:333)
    at org.jboss.netty.channel.Channels.fireChannelConnected(Channels.java:227)
    at org.jboss.netty.channel.socket.nio.NioWorker$RegisterTask.run(NioWorker.java:187)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processRegisterTaskQueue(AbstractNioWorker.java:430)
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:329)
    at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.net.SocketException: Connection timed out
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3345)
    ... 17 more

But i have already put auto reconnect = true to my JDBC. 但是我已经将auto reconnect = true应用于我的JDBC。 and also am using OrderedMemoryAwareThreadPoolExecutor 并且也在使用OrderedMemoryAwareThreadPoolExecutor

ExecutionHandler channelExecutionHandler = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(Runtime.getRuntime()
                .availableProcessors(), 0, 0)); 

I use awaituninteruptable function to close a channel. 我使用awaituninteruptable函数关闭通道。 like 喜欢

ctx.getChannel().write(new ErrMessage(e.getChannel().getRemoteAddress().toString()).getEncodedMessage())

Is this causing any type of infinite loop activity. 这是否导致任何类型的无限循环活动。 Now the present situation is server accept the coonections and do not process any kind of message.We have worker thread and boss. 现在的情况是服务器接受连接并且不处理任何类型的消息。我们有工作线程和上司。 But the logging handler works fine. 但是日志记录处理程序工作正常。 Am using snaq.db.connection pool for maintaining DB Connections. 我正在使用snaq.db.connection池维护数据库连接。

You seem to use MySQL connection quite straight-forward with DriverManager.getConnection() . 您似乎很直接地将MySQL连接与DriverManager.getConnection() Therefore you either don't close opened connection at all, or create so many connections, that MySQL server's limit is exceeded. 因此,您要么根本不关闭打开的连接,要么创建太多的连接,以致超出了MySQL服务器的限制。

In highly-concurrent environment (and Netty certainly is implemented for that) I would strongly recommend using database connection pools: c3p0 or commons-dbcp . 在高度并行的环境中(并且肯定为此实现了Netty),我强烈建议使用数据库连接池: c3p0commons-dbcp With proper settings you may avoid MySQL connections issues. 使用正确的设置,您可以避免MySQL连接问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM