Skip to content

[AI] Fix timeout issue during connection establishment (#193) #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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();
}
}
}
}