[#5893] Ensure we not close NioDatagramChannel when SocketException is received.
Motivation: When using java.nio.DatagramChannel we should not close the channel when a SocketException was thrown as we can still use the channel. Modifications: Not close the Channel when SocketException is thrown Result: More robust and correct handling of exceptions when using NioDatagramChannel.
This commit is contained in:
parent
a09e56850e
commit
e102a008b6
@ -97,11 +97,7 @@ public abstract class AbstractNioMessageChannel extends AbstractNioChannel {
|
|||||||
pipeline.fireChannelReadComplete();
|
pipeline.fireChannelReadComplete();
|
||||||
|
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
if (exception instanceof IOException && !(exception instanceof PortUnreachableException)) {
|
closed = closeOnReadError(exception);
|
||||||
// ServerChannel should not be closed even on IOException because it can often continue
|
|
||||||
// accepting incoming connections. (e.g. too many open files)
|
|
||||||
closed = !(AbstractNioMessageChannel.this instanceof ServerChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
pipeline.fireExceptionCaught(exception);
|
pipeline.fireExceptionCaught(exception);
|
||||||
}
|
}
|
||||||
@ -175,6 +171,14 @@ public abstract class AbstractNioMessageChannel extends AbstractNioChannel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean closeOnReadError(Throwable cause) {
|
||||||
|
// ServerChannel should not be closed even on IOException because it can often continue
|
||||||
|
// accepting incoming connections. (e.g. too many open files)
|
||||||
|
return cause instanceof IOException &&
|
||||||
|
!(cause instanceof PortUnreachableException) &&
|
||||||
|
this instanceof ServerChannel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read messages into the given array and return the amount which was read.
|
* Read messages into the given array and return the amount which was read.
|
||||||
*/
|
*/
|
||||||
|
@ -595,4 +595,14 @@ public final class NioDatagramChannel
|
|||||||
void clearReadPending0() {
|
void clearReadPending0() {
|
||||||
clearReadPending();
|
clearReadPending();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean closeOnReadError(Throwable cause) {
|
||||||
|
// We do not want to close on SocketException when using DatagramChannel as we usually can continue receiving.
|
||||||
|
// See https://github.com/netty/netty/issues/5893
|
||||||
|
if (cause instanceof SocketException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.closeOnReadError(cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user