OpenAPI: Retry REST test server start on wrapped BindException#17109
Open
wombatu-kun wants to merge 1 commit into
Open
OpenAPI: Retry REST test server start on wrapped BindException#17109wombatu-kun wants to merge 1 commit into
wombatu-kun wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RESTServerExtension#beforeAllstarts an embedded REST catalog server for tests on an OS-assigned free port (RCKUtils.findFreePort()opensServerSocket(0), reads the port, and closes it). Because Jetty binds to that port only later inhttpServer.start(), there is a TOCTOU window in which a parallel test JVM fork can grab the same ephemeral port, producingjava.net.BindException: Address already in use.PR #13017 added a 10-attempt retry to paper over that window, but it never fires. It re-rolls the port only inside
catch (BindException e), while Jetty surfaces the failure as ajava.io.IOException("Failed to bind to ...")whose cause is the realBindException. SinceIOExceptionis not aBindException, control falls through to the genericcatch (Exception e), which rethrows immediately with no retry, so a single lost port race aborts the whole test class withinitializationError.This changes the catch to detect a bind failure by scanning the exception's cause chain, so the existing retry actually re-rolls the port on a wrapped
BindException. The deeper TOCTOU window is inherent to probe-then-bind and is left as-is; retry is the agreed mitigation. This is a follow-up to the two earlier attempts at this same flakiness: #13017 (add the retry) and #13992 (enableSO_REUSEPORT, which only covers theTIME_WAITcase, not an active bind by another fork).Observed as a flaky failure of
TestAddFilesProcedure > initializationErrorin thespark-tests (17, 3.5, 2.12, extensions)job (which then fail-fast cancels the siblingcorejobs), e.g. on the unrelated PR #17065: https://github.com/apache/iceberg/actions/runs/28645321282/job/84950457116Testing
Added
TestRESTServerExtensioncovering the cause-chain detection: the exact CI shape (anIOExceptionwrapping aBindException, asserting it is not itself aBindExceptionso a directcatchwould miss it), a directBindException, non-bind failures, andnull.