Skip to content

Commit 44b86eb

Browse files
committed
IOSessionImpl: Support CloseMode.IMMEDIATE for Unix domain sockets
It's fine to set socket linger on a Unix-domain socket as long as it is done through the `SocketChannel` API. Calling `.socket()` always throws on a UDS-backed `SocketChannel`, however, which was silently causing issues for `TestAsyncSocketTimeout`, as connections were being left open until timeout.
1 parent 1253c7f commit 44b86eb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import java.io.IOException;
3131
import java.net.SocketAddress;
32-
import java.net.SocketException;
32+
import java.net.StandardSocketOptions;
3333
import java.nio.ByteBuffer;
3434
import java.nio.channels.ByteChannel;
3535
import java.nio.channels.SelectionKey;
@@ -266,8 +266,8 @@ public void close(final CloseMode closeMode) {
266266
if (this.status.compareAndSet(Status.ACTIVE, Status.CLOSED)) {
267267
if (closeMode == CloseMode.IMMEDIATE) {
268268
try {
269-
this.channel.socket().setSoLinger(true, 0);
270-
} catch (final SocketException e) {
269+
this.channel.setOption(StandardSocketOptions.SO_LINGER, 0);
270+
} catch (final UnsupportedOperationException | IOException e) {
271271
// Quietly ignore
272272
}
273273
}

0 commit comments

Comments
 (0)