Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void initialize() throws IOException {
if (serverSocket == null || serverSocket.isClosed()) {
throw new IOException("TransportHandler not preinitialized");
}
serverSocket.setSoTimeout((int) timeout);
socket = serverSocket.accept();
socket.setSoTimeout((int) timeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.rub.nds.tlsattacker.util.FreePortFinder;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketTimeoutException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -91,4 +92,26 @@ public void fullTest() throws IOException {
assertArrayEquals(new byte[] {4, 3, 2, 1}, received);
}
}

/** Test that serverSocket.accept() timeout works correctly */
@Test
public void testAcceptTimeout() throws IOException {
// Create handler with short timeout
ServerTcpTransportHandler timeoutHandler =
new ServerTcpTransportHandler(500, 500, FreePortFinder.getPossiblyFreePort());
try {
timeoutHandler.preInitialize();
// Try to initialize without connecting - should timeout
assertThrows(
SocketTimeoutException.class,
() -> {
timeoutHandler.initialize();
});
} finally {
if (timeoutHandler.getServerSocket() != null
&& !timeoutHandler.getServerSocket().isClosed()) {
timeoutHandler.getServerSocket().close();
}
}
}
}