Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException sometimes (very few times) with an encoder #1980

Closed
flozano opened this issue Nov 13, 2013 · 13 comments
Closed

ClassCastException sometimes (very few times) with an encoder #1980

flozano opened this issue Nov 13, 2013 · 13 comments

Comments

@flozano
Copy link
Contributor

flozano commented Nov 13, 2013

10:52:55.674 [nioEventLoopGroup-4-2] WARN  i.n.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
java.lang.ClassCastException: com.notnoop.apns.EnhancedApnsNotification cannot be cast to io.netty.buffer.ByteBuf
        at io.netty.handler.ssl.SslHandler.flush0(SslHandler.java:435) ~[netty-all-4.0.12.Final.jar:na]
        at io.netty.handler.ssl.SslHandler.flush(SslHandler.java:420) ~[netty-all-4.0.12.Final.jar:na]
        at io.netty.channel.DefaultChannelHandlerContext.invokeFlush(DefaultChannelHandlerContext.java:675) [netty-all-4.0.12.Final.jar:na]
        at io.netty.channel.DefaultChannelHandlerContext.access$1600(DefaultChannelHandlerContext.java:29) [netty-all-4.0.12.Final.jar:na]
        at io.netty.channel.DefaultChannelHandlerContext$WriteTask.run(DefaultChannelHandlerContext.java:908) [netty-all-4.0.12.Final.jar:na]
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354) [netty-all-4.0.12.Final.jar:na]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353) [netty-all-4.0.12.Final.jar:na]
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101) [netty-all-4.0.12.Final.jar:na]
        at java.lang.Thread.run(Unknown Source) [na:1.7.0_45]

ApnsNotificationEncoder extends MessageToByteEncoder, registered and working 99,999% of the time, ApnsNotification is an interface implemented by EnhancedApnsNotification, and I only have one channel.write() in the whole code. Am I doing something wrong, or maybe there is a problem with matching interfaces/classes-implementing-interfaces in encoder pipeline?

@trustin
Copy link
Member

trustin commented Nov 14, 2013

To me, it seems like you are trying to write something that is not ByteBuf to SslHandler. Because SslHandler does not understand anything but ByteBuf, it fails with ClassCastException when it encounters an unsupported message.

Do you manipulate your pipeline dynamically? Then, there might be some race condition such as writing a message object before you insert your MessageToByteEncoder.

If you still think this is a bug in Netty, please feel free to reopen this issue with some test case or your pipeline setup + handler implementation.

@trustin trustin closed this as completed Nov 14, 2013
@flozano
Copy link
Contributor Author

flozano commented Nov 14, 2013

I write a EnhancedApnsNotification and expect my ApnsNotificationEncoder to encode it. I don't modify the pipeline on-the-fly, the only part I touch the pipeline s the channel initialization code.

I can't reproduce it in a test case because it happens very few times (1-2 times in thousands of executions), and under circumstances I am yet to determine, but to me it looks like it's a netty bug.

@trustin
Copy link
Member

trustin commented Nov 14, 2013

Then, could you please paste your channel initializer?

@trustin trustin reopened this Nov 14, 2013
@normanmaurer
Copy link
Member

@trustin you are looking into it ?

For me it looks like the Encoder is somehow removed in between. I think the only way this could happen is when the channel closes as part of the ChannelPipeline cleanup ,but not sure how this could raise with the write here.

@trustin
Copy link
Member

trustin commented Nov 14, 2013

I tried to reproduce the problem with the modified SecureChat example without success so far. I made the following modifications to the SecureChat example:

  • Modify SecureChatServerHandler not to send anything.
  • Modify SecureChatClient.main() to make a connection attempt, write a single line of message, and then disconnect. Wrap it in an infinite loop.

@trustin
Copy link
Member

trustin commented Nov 14, 2013

@normanmaurer That sounds like the right guess, looking from the log message?

@normanmaurer
Copy link
Member

yeah I just wonder how it could race here... hmmm

@normanmaurer
Copy link
Member

@flozano was you able to get more details on this ?

@flozano
Copy link
Contributor Author

flozano commented Mar 11, 2014

Unfortunately no :(

@normanmaurer
Copy link
Member

@flozano so it still happens ? If we could have some way to produce it would be quite easier :(

@flozano
Copy link
Contributor Author

flozano commented Mar 11, 2014

No, we can't reproduce now. It happened VERY few times.

@normanmaurer
Copy link
Member

@flozano I will close this for now ... please re-open if it still happens with the latest release and provide infos how to reproduce

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

No branches or pull requests

3 participants