[#5893] Ensure we not close NioDatagramChannel when SocketException i… #5899

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@normanmaurer
Member
normanmaurer commented Oct 6, 2016 edited

…s 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.

@normanmaurer normanmaurer added the defect label Oct 6, 2016
@normanmaurer normanmaurer added this to the 4.0.42.Final milestone Oct 6, 2016
@normanmaurer normanmaurer self-assigned this Oct 6, 2016
@@ -175,6 +171,15 @@ protected boolean continueOnWriteError() {
return false;
}
+ protected boolean closeOnReadError(Throwable cause) {
+ if (cause instanceof IOException && !(cause instanceof PortUnreachableException)) {
@Scottmitch
Scottmitch Oct 6, 2016 Member

simplify to:

return cause instanceof IOException &&
       !(cause instanceof PortUnreachableException) &&
       this instanceof ServerChannel
+
+ @Override
+ protected boolean closeOnReadError(Throwable cause) {
+ // We not want to close on SocketException when using DatagramChannel as we usually can continue receiving.
@Scottmitch
Scottmitch Oct 6, 2016 Member

We not want to close -> We do not want to close

@Scottmitch
Member

is is possible to have a unit test for this?

@normanmaurer
Member

@Scottmitch I can not think of a way :(

@@ -175,6 +171,15 @@ protected boolean continueOnWriteError() {
return false;
}
+ protected boolean closeOnReadError(Throwable cause) {
+ if (cause instanceof IOException && !(cause instanceof PortUnreachableException)) {
@nmittler
nmittler Oct 7, 2016 Member

@normanmaurer what about RuntimeExceptions or Errors? Should we close in that case as well?

@normanmaurer
normanmaurer Oct 9, 2016 Member

@nmittler We did not before, so I think no

@nmittler

LGTM

@normanmaurer normanmaurer [#5893] Ensure we not close NioDatagramChannel when SocketException i…
…s 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.
672c86d
@normanmaurer
Member

Cherry-picked into 4.1 (e102a00) and 4.0 (71b8960)

@normanmaurer normanmaurer deleted the nio_datagram_close branch Oct 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment