之前,我们使用 Netty 4.0.0.Alpha7 开发我们的 Websocket 应用程序,一切正常。Netty 4.0.0.Beta1 发布后,我们将它们合并到我们的应用程序中。但是,没有客户端可以连接到应用程序。最初,我认为这是我们的问题,所以我们从 github 获取了 websocket 示例,但它也不起作用。
奇怪的是,当我们在本地机器上运行时,我们的应用程序和示例可以正常工作,但是一旦部署到我们的服务器上,它就无法工作。当我们在同一台服务器上回滚到 Netty Alpha7 时,它又可以正常工作了。有没有人遇到过这种问题?
这是我在我们的服务器(Linux)中运行 Websocket 示例时发现的异常。当我在本地机器(Windows7)上运行时没有发现这个异常
io.netty.channel.ChannelPipelineException: io.netty.buffer.IllegalBufferAccessException
at io.netty.channel.DefaultChannelPipeline.notifyHandlerException(DefaultChannelPipeline.java:1019)
at io.netty.channel.DefaultChannelHandlerContext.freeHandlerBuffersAfterRemoval(DefaultChannelHandlerContext.java:360)
at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:962)
at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926)
at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:904)
at io.netty.channel.DefaultChannelPipeline.fireInboundBufferUpdated(DefaultChannelPipeline.java:909)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:115)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:401)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:365)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:302)
at io.netty.channel.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:110)
at java.lang.Thread.run(Thread.java:619)
Caused by: io.netty.buffer.IllegalBufferAccessException
at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:81)
at io.netty.channel.ChannelInboundByteHandlerAdapter.freeInboundBuffer(ChannelInboundByteHandlerAdapter.java:46)
at io.netty.channel.DefaultChannelHandlerContext.freeHandlerBuffersAfterRemoval(DefaultChannelHandlerContext.java:358)
... 10 more
io.netty.channel.ChannelPipelineException: io.netty.buffer.IllegalBufferAccessException
at io.netty.channel.DefaultChannelPipeline.notifyHandlerException(DefaultChannelPipeline.java:1019)
at io.netty.channel.DefaultChannelHandlerContext.freeHandlerBuffersAfterRemoval(DefaultChannelHandlerContext.java:360)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelInactive(DefaultChannelHandlerContext.java:823)
at io.netty.channel.DefaultChannelHandlerContext.access$1300(DefaultChannelHandlerContext.java:38)
at io.netty.channel.DefaultChannelHandlerContext$5.run(DefaultChannelHandlerContext.java:808)
at io.netty.channel.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:259)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:305)
at io.netty.channel.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:110)
at java.lang.Thread.run(Thread.java:619)
Caused by: io.netty.buffer.IllegalBufferAccessException
at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:81)
at io.netty.channel.ChannelInboundByteHandlerAdapter.freeInboundBuffer(ChannelInboundByteHandlerAdapter.java:46)
at io.netty.channel.DefaultChannelHandlerContext.freeHandlerBuffersAfterRemoval(DefaultChannelHandlerContext.java:358)
... 7 more
更新,看来这是java版本的问题。最初,java 版本是 6u17,应用程序无法运行。将其更新到 6u38 后,应用程序运行良好。