GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — SSLHandler io.netty.buffer.IllegalBufferAccessException · Issue #1054 · netty/netty

SSLHandler io.netty.buffer.IllegalBufferAccessException #1054

New issue
Copy link
New issue
Copy link
Closed
Closed
SSLHandler io.netty.buffer.IllegalBufferAccessException#1054
Copy link
Assignees
normanmaurer
Labels
not a bug

Description

@tah-mas
tah-mas
opened on Feb 15, 2013
Issue body actions

Hello,

I just updated my server to use netty-4.0.0.Beta1 and I now get the below exception then clients are trying to access the server. This all worked without any problems on the ALPHA8 release.

My pipeline:
public void initChannel(final SocketChannel ch) throws Exception { // NOPMD

    try {
         ChannelPipeline pipeline = ch.pipeline();

         if(isEnableSSL()) {

             SSLEngine engine = NetworkingSSLContextFactory.getServerContext().createSSLEngine();
             engine.setUseClientMode(false);
             SslHandler sslHandler =  new SslHandler(engine, true);
             sslHandler.setHandshakeTimeoutMillis(Constants.NETWORK_HANDSHAKE_TIMEOUT_MILLIS);
             sslHandler.setCloseNotifyTimeoutMillis(ServerConstants.NETWORK_CLOSE_NOTIFY_TIMEOUT_MILLIS);
             pipeline.addLast("ssl", sslHandler);
         }

         pipeline.addLast("decoder", new HttpRequestDecoder());
         pipeline.addLast("aggregator", new HttpObjectAggregator(Integer.MAX_VALUE));
         pipeline.addLast("encoder", new HttpResponseEncoder());
         pipeline.addLast(SECURITY_NAME, securityHandler);
         pipeline.addLast("externalIPHandler", ipHandler);
         //hearbeats -- checkout the user event in the server handler
         pipeline.addLast(pingExecutor, "idleState", new IdleStateHandler(readTimeout, writeTimeout, ServerConstants.CHANNEL_TIMEOUT_SECONDS, TimeUnit.SECONDS));

         pipeline.addLast("handler", serverHandler);
    } catch (Throwable t) {

        logger.log(Level.SEVERE, "Caught error in pipeline", t);
    }
 }

And the exception.

WARNING: Exception caught handling request
io.netty.buffer.IllegalBufferAccessException
at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:81)
at io.netty.handler.codec.http.DefaultFullHttpRequest.release(DefaultFullHttpRequest.java:69)
at io.netty.buffer.BufUtil.release(BufUtil.java:71)
at io.netty.channel.ChannelInboundMessageHandlerAdapter.inboundBufferUpdated(ChannelInboundMessageHandlerAdapter.java:109)
at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951)
at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926)
at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:904)
at io.netty.channel.ChannelInboundMessageHandlerAdapter.inboundBufferUpdated(ChannelInboundMessageHandlerAdapter.java:116)
at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951)
at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926)
at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:904)
at io.netty.channel.ChannelInboundMessageHandlerAdapter.inboundBufferUpdated(ChannelInboundMessageHandlerAdapter.java:116)
at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951)
at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926)
at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:904)
at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:466)
at io.netty.handler.codec.ByteToMessageDecoder.inboundBufferUpdated(ByteToMessageDecoder.java:69)
at io.netty.channel.ChannelInboundByteHandlerAdapter.inboundBufferUpdated(ChannelInboundByteHandlerAdapter.java:51)
at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951)
at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926)
at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:904)
at io.netty.handler.ssl.SslHandler.inboundBufferUpdated(SslHandler.java:840)
at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951)
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:680)

Any help appreciated.

Thanks,
T

Activity

  1. normanmaurer commented on Feb 16, 2013

    @normanmaurer
    normanmaurer
    on Feb 16, 2013
    Member
    More actions

    @tah-mas do you by any chance write the same DefaultFullHttpRequest multiple times ?

  2. tah-mas commented on Feb 18, 2013

    @tah-mas
    tah-mas
    on Feb 18, 2013
    Author
    More actions

    No I don't think so. I'm not very experienced with netty so I may be doing something wrong but I have written a small test server / client which you can use to replicate the error.

    It's an eclipse project so you can just import it and run up the TestServer / Client and you should see the error in the server console.

    Test project:
    https://dl.dropbox.com/u/17207363/netty/Netty4Test.tar.gz

    Thanks,
    Tah-mas

  3. normanmaurer commented on Feb 18, 2013

    @normanmaurer
    normanmaurer
    on Feb 18, 2013
    Member
    More actions

    Thanks will have a look soon …


    Norman Maurer
    [email protected]

    JBoss, by Red Hat

    Am 18.02.2013 um 13:55 schrieb tah-mas [email protected]:

    No I don't think so. I'm not very experienced with netty so I may be doing something wrong but I have written a small test server / client which you can use to replicate the error.

    It's an eclipse project so you can just import it and run up the TestServer / Client and you should see the error in the server console.

    Test project:
    https://dl.dropbox.com/u/17207363/netty/Netty4Test.tar.gz

    Thanks,
    Tah-mas

    —
    Reply to this email directly or view it on GitHub.

  4. normanmaurer commented on Feb 19, 2013

    @normanmaurer
    normanmaurer
    on Feb 19, 2013
    Member
    More actions

    @tah-mas this is because of the changes we introduces regarding free buffers automatically when a ChannelHandler is removed from the ChannelPipeline. This is needed because otherwise we would risk memory leaks. So once you call ChannelPipeline.remove(..) you are not allowed to access the content of the buffer anymore. Because of this we added an extra method to ChannelPipeline that allow you to remove the ChannelHandler and forward the content of the buffer to the next in the ChannelPipeline. You see it in action in the following diff which also fix your problem:

    --- src/com/test/netty/ExternalIPHandler.java   2013-02-19 07:09:04.000000000 +0100
    +++ src/com/test/netty/ExternalIPHandlerFixed.java  2013-02-19 07:10:35.000000000 +0100
    @@ -39,16 +39,7 @@
    
                    MessageSender.sendHttpResponse(ctx, resp, false);
                } else {
    -               
    -               ctx.pipeline().remove(this);
    -               forwardMessage = true;
    -           }
    -
    -           if(forwardMessage) {
    -
    -               //the below forwards the message in the chain..
    -               ctx.nextInboundMessageBuffer().add(req);
    -               //ctx.fireInboundBufferUpdated();
    +                ctx.pipeline().removeAndForward(this);
                }
            } catch (Throwable t) {
    
    
  5. ghost assigned
    normanmaurer
    on Feb 19, 2013
  6. normanmaurer
    closed this as completedon Feb 19, 2013
  7. tah-mas commented on Feb 19, 2013

    @tah-mas
    tah-mas
    on Feb 19, 2013
    Author
    More actions

    That does indeed fix the problem. Thank you very much Norman!

  8. tah-mas commented on Feb 19, 2013

    @tah-mas
    tah-mas
    on Feb 19, 2013
    Author
    More actions

    Hi again Norman,

    Spoke to soon. If I use the removeAndForward method the message does not get forwarded to the next handler in the chain. I have updated the test to reflect this and you will now see:

    Feb 19, 2013 6:01:25 PM com.test.netty.TestServer start INFO: TestServer started on port 8443 using SSL.
    Feb 19, 2013 6:01:32 PM com.test.netty.ExternalIPHandler messageReceived INFO: #### Custom handler 1 invoked ####
    Feb 19, 2013 6:01:33 PM com.test.netty.ExternalIPHandler messageReceived INFO: #### Custom handler 1 invoked ####
    Feb 19, 2013 6:01:33 PM com.test.netty.ExternalIPHandler messageReceivedINFO: #### 1 Called ctx.pipeline().removeAndForward(this) ####

    and nothing else. This is there I would expect to see custom handler 2, 3 and 4 being invoked.

    If I subsequently comment out the ExternalIPHandler from the pipeline in the ServerInitializer and restart the server custom hander 2, 3 and 4 are being invoked but I am back to the io.netty.buffer.IllegalBufferAccessException:

    eb 19, 2013 6:02:11 PM com.test.netty.TestServer start
    INFO: TestServer started on port 8443 using SSL.
    Feb 19, 2013 6:02:21 PM com.test.netty.PingHandler messageReceived INFO: #### Custom handler 2 invoked ####
    Feb 19, 2013 6:02:21 PM com.test.netty.SecurityHandler messageReceived INFO: #### Custom handler 3 invoked ####
    Feb 19, 2013 6:02:21 PM com.test.netty.ServerHandler messageReceived INFO: #### Custom handler 4 invoked ####
    Feb 19, 2013 6:02:21 PM com.test.netty.ServerHandler exceptionCaught WARNING: Exception caught handling request
    io.netty.buffer.IllegalBufferAccessException
    at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:81)
    at io.netty.handler.codec.http.DefaultFullHttpRequest.release(DefaultFullHttpRequest.java:69)
    at io.netty.buffer.BufUtil.release(BufUtil.java:71)
    at io.netty.channel.ChannelInboundMessageHandlerAdapter.inboundBufferUpdated(ChannelInboundMessageHandlerAdapter.java:109)
    at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951)
    at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926)
    at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:904)
    at com.test.netty.PingHandler.messageReceived(PingHandler.java:24)
    at com.test.netty.PingHandler.messageReceived(PingHandler.java:1)
    at io.netty.channel.ChannelInboundMessageHandlerAdapter.inboundBufferUpdated(ChannelInboundMessageHandlerAdapter.java:104)
    at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951)
    at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926)
    at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:904)
    at io.netty.channel.ChannelInboundMessageHandlerAdapter.inboundBufferUpdated(ChannelInboundMessageHandlerAdapter.java:116)
    at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951)
    at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926)
    at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:904)
    at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:466)
    at io.netty.handler.codec.ByteToMessageDecoder.inboundBufferUpdated(ByteToMessageDecoder.java:69)
    at io.netty.channel.ChannelInboundByteHandlerAdapter.inboundBufferUpdated(ChannelInboundByteHandlerAdapter.java:51)
    at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951)
    at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:926)
    at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:904)
    at io.netty.handler.ssl.SslHandler.inboundBufferUpdated(SslHandler.java:840)
    at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:951)
    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:680)

    The result I am after is:

    1st request -> ExternalIPHandler
    2nd request -> ExternalIP Hander -> PingHandler -> Security Handler -> ServerHandler and no exception.
    3rd etc (not in the test) Should hit PingHandler -> Security Handler -> ServerHandler

    Any ideas? You can download the updated test from:
    https://dl.dropbox.com/u/17207363/netty/Netty4Test_v01.tar.gz

    Thanks,
    tah-mas

  9. normanmaurer commented on Feb 19, 2013

    @normanmaurer
    normanmaurer
    on Feb 19, 2013
    Member
    More actions

    @tah-mas there are two problems here...

    1. I think the problem you see with my patched version is fixed in current master. Please use latest 4.0.0.Beta2-SNAPSHOT and test
    2. In your ping handler you not consume the FullHttpRequest but just forward it. In that case you need call FullHttpRequest.retain() to make sure it is not released
  10. tah-mas commented on Feb 19, 2013

    @tah-mas
    tah-mas
    on Feb 19, 2013
    Author
    More actions

    Hi Norman.

    Using the snapshot build (Feb 19, 2013 7:02:47 AM) I still see the problem with removeAndForward (#1). Using retain fixed the #2 problem.

    Thanks,
    tah-mas

  11. rampradeepk commented on Apr 9, 2013

    @rampradeepk
    rampradeepk
    on Apr 9, 2013
    More actions

    @tah-mas , @normanmaurer
    Running into a similiar issue on using Unpooled buffers. Can you share the updated code base? I could not access the dropbox files as well. Can you share them as well?

    Here is the exception:
    io.netty.buffer.IllegalBufferAccessException: null
    at io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1132) ~[netty-all-4.0.0.CR2.jar:na]
    at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1118) ~[netty-all-4.0.0.CR2.jar:na]
    at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:684) ~[netty-all-4.0.0.CR2.jar:na]
    at io.netty.buffer.ByteBufInputStream.read(ByteBufInputStream.java:120) ~[netty-all-4.0.0.CR2.jar:na]
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283) ~[na:1.7.0_04]
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325) ~[na:1.7.0_04]
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177) ~[na:1.7.0_04]
    at java.io.InputStreamReader.read(InputStreamReader.java:184) ~[na:1.7.0_04]
    at java.io.Reader.read(Reader.java:140) ~[na:1.7.0_04]

    Thanks,
    Rampradeep.

  12. trustin commented on Apr 10, 2013

    @trustin
    trustin
    on Apr 10, 2013
    Member
    More actions

    @rampradeepk I am not sure your problem is related with this issue. Can you file a separate issue with the detailed instructions to reproduce the problem? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @normanmaurer
    normanmaurer

Labels

not a bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.