Skip to content

Commit 932cafe

Browse files
mtopolnikclaude
andcommitted
Document TOCTOU race in findUnusedPort()
Add a comment to findUnusedPort() explaining why the TOCTOU race between closing the ServerSocket and the caller's connect attempt is acceptable. Every caller is a negative test that expects the connection to fail, so a stolen port produces the same outcome. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 33e5796 commit 932cafe

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

core/src/test/java/io/questdb/client/test/cutlass/qwp/client/LineSenderBuilderWebSocketTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,11 @@ private static void assertThrowsAny(Runnable action, String... anyOf) {
725725
}
726726
}
727727

728+
// There is a TOCTOU race between closing the ServerSocket and the caller's
729+
// connect attempt — another process could bind the port in between. This is
730+
// acceptable because every caller is a negative test that expects the connection
731+
// to fail. If the port is stolen, the test connects to a non-QuestDB endpoint,
732+
// which also fails with the same error.
728733
private static int findUnusedPort() throws Exception {
729734
try (java.net.ServerSocket s = new java.net.ServerSocket(0)) {
730735
return s.getLocalPort();

0 commit comments

Comments
 (0)