Only try to obtain SO_LINGER on close if fd is still open.

Motivation:

When try to get SO_LINGER from a fd that is closed an Exception is thrown. We should only try to get SO_LINGER if the fd is still open otherwise an Exception is thrown that can be ignored anyway.

Modifications:

First check if the fd is still open before try to obtain SO_LINGER setting when get the closeExecutor. This is also the same that we do in the NIO transport.

Result:

No more exception when calling unsafe.close() on a channel that has a closed file descriptor.
This commit is contained in:
Norman Maurer 2015-08-27 10:29:19 +02:00
parent 09dff41343
commit dab20ccdb6

View File

@ -197,7 +197,9 @@ public final class EpollSocketChannel extends AbstractEpollStreamChannel impleme
private final class EpollSocketChannelUnsafe extends EpollStreamUnsafe {
@Override
protected Executor closeExecutor() {
if (config().getSoLinger() > 0) {
// Check isOpen() first as otherwise it will throw a RuntimeException
// when call getSoLinger() as the fd is not valid anymore.
if (isOpen() && config().getSoLinger() > 0) {
return GlobalEventExecutor.INSTANCE;
}
return null;