Description
Netty version: 5.0.0-Alpha2-SNAPSHOT (28/02/2015 jar)
Attention: @normanmaurer
Related issue: #3443
Event Loop: Epoll ET (issue would also occur on LT)
Hi guys,
I've found another case whereby an Invalid file descriptor exception can occur, which triggers an endless loop of epollInReady()
calls.
The stack trace is exactly the same as in issue #3443 (if I could have re-opened that issue, I would have).
The fix norman supplied before helps, but doesn't solve all cases. The underlying issue is that epollInReady
does not check to see if the channel is open before reading from it or before scheduling another epollInReady
call.
Example:
- Channel is active and socket contains 50KB of data
epollInReady
is called and reads 1KB of data into a buffer and triggerspipeline.fireChannelRead
- A handler in the pipeline closes the channel for whatever reason (e.g.
SslHandler
closes the channel due to handshake failure). epollInReady
will attempt to read more data from the socket (as it is in ado-while
loop), but will throw anjava.lang.IllegalStateException: invalid file descriptor
as the previous iteration of the loop closed the channelepollInReady
will enter thecatch
clause (due to theIllegalStateException
) and reschedule a newepollInReady
event- The new
epollInReady
event will be triggered and attempt to read from the socket causing anotherjava.lang.IllegalStateException: invalid file descriptor
and the cycle will continue
I believe there are a few places that need to check if the channel is still open before attempting to read.
- The
do-while
loop should exit if the channel is no longer open - this prevents attempting to make a subsequent read from a closed socket - The
catch
clause should not schedule anotherepollInReady
if the socket is already closed - The
Runnable
task should not callepollInReady
if the socket is already closed
I might have gone a bit overboard adding the check to all these places, so I'd appreciate it if someone would confirm if I am correct about this or not.
Activity