Skip to content

feat(rest): align HTTP retries and timeouts with Java - #1060

Open
zhjwpku wants to merge 7 commits into
apache:mainfrom
zhjwpku:rest-http-client-transport
Open

zhjwpku wants to merge 7 commits into
apache:mainfrom
zhjwpku:rest-http-client-transport

Conversation

@zhjwpku

@zhjwpku zhjwpku commented Oct 25, 2026

Copy link
Copy Markdown
Member

Configure REST transport through rest.client.* properties for connection and socket timeouts, retry limits, user-agent and idempotency-key lifetime. Apply initial and merged catalog properties through the client factory, preserving custom factories and the existing timeout constructor.

Use Java's three-minute default connection timeout and zero-value timeout semantics. Enforce response inactivity deadlines in milliseconds with a synchronous libcurl transfer loop, without an additional executor.

Authenticate once and replay the same request across retries. Decide HTTP status retries after headers and before reading the entity. Honor Idempotency-Key for retry-safe requests and bound keyed retries by the first-send time and maximum next interval, including Retry-After or jitter. Parse key lifetimes as ISO-8601 durations with Java-compatible handling of invalid and non-positive values.

Retry eligible request-execution I/O failures without a delay. Propagate final response-body failures without replaying the request. Preserve redirect protection, transfer-error reporting and commit-state-unknown handling. Saturate oversized Retry-After conversions without overflow and avoid echoing malformed OAuth token responses.

Document the transport policy and add regression coverage for retry rules, key lifetime budgets, stable authentication, timeout precision and duration boundaries.

@zhjwpku
zhjwpku force-pushed the rest-http-client-transport branch 2 times, most recently from c6b2a80 to 2e15601 Compare October 29, 2026 14:34
@zhjwpku
zhjwpku marked this pull request as ready for review October 29, 2026 15:38
Comment thread src/iceberg/catalog/rest/http_client.cc Outdated
Comment on lines +322 to +324
if (response.status_code != 0 || !safe ||
!IsRetriableTransportError(response.error.code)) {
return false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nonzero status is available before the final header block is complete. A TCP reset in that window is still an execution-stage failure that Java retries for safe requests, but this condition suppresses it. Track final-header completion and add a partial-header reset test, while keeping body-read failures non-retryable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by tracking final-header completion explicitly. Partial-header resets can retry safe requests; body-read failures remain non-retryable. Added regression tests for both cases.

Comment thread mkdocs/docs/rest-catalog.md Resolved
return std::chrono::milliseconds(std::max<int64_t>(0, properties.Get(entry)));
};
ICEBERG_ASSIGN_OR_RAISE(auto options,
HttpClientOptions::FromProperties(properties.configs()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass the top-level idempotency-key-lifetime from /v1/config into the retry policy. Only let a key enable POST retries if the server advertises support. A server that ignores the key can apply the write twice.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The top-level config field now controls key-based retries. Client properties, defaults and overrides cannot enable support or extend the advertised window. Added configuration and retry coverage.

Comment thread src/iceberg/catalog/rest/http_client.cc Outdated
const auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::time_point_cast<std::chrono::milliseconds>(now) - first_attempt);
if (!attempt.retry_approved &&
!ShouldRetry(attempt.response, request, exec_count, options, elapsed, now)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the retry decision made at the end of the final headers. This second check lets a Retry-After trailer on a 503 replay a POST without an idempotency key.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retry decision is now fixed at final-header completion. A Retry-After trailer cannot enable a POST retry. Added a regression test.

return std::move(attempt.response);
}
const auto delay = RetryInterval(attempt.response, exec_count, timing.now());
if (delay > std::chrono::milliseconds::zero()) timing.sleep(delay);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the key's expiry again just before sending the retry. Response cleanup or an oversleep can take the next attempt past the server's reuse window.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expiry is checked after response cleanup and again after waiting, before resending.

if (seconds > kMaxSeconds) return (std::chrono::milliseconds::max)();
return std::chrono::milliseconds(seconds * 1000);
}
const auto date = curl_getdate(it->second.c_str(), nullptr);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only accept HTTP-date formats here. curl_getdate accepts 01 Jan 2035, so an invalid Retry-After can make the client wait years. Use the normal backoff for that value.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restricted.

@zhjwpku
zhjwpku force-pushed the rest-http-client-transport branch from cfabc7d to c9b0908 Compare November 22, 2026 23:58
Configure REST transport through rest.client.* properties for connection
and socket timeouts, retry limits, user-agent and idempotency-key lifetime.
Apply initial and merged catalog properties through the client factory,
preserving custom factories and the existing timeout constructor.

Use Java's three-minute default connection timeout and zero-value timeout
semantics. Enforce response inactivity deadlines in milliseconds with a
synchronous libcurl transfer loop, without an additional executor.

Authenticate once and replay the same request across retries. Decide HTTP
status retries after headers and before reading the entity. Honor
Idempotency-Key for retry-safe requests and bound keyed retries by the
first-send time and maximum next interval, including Retry-After or jitter.
Parse key lifetimes as ISO-8601 durations with Java-compatible handling of
invalid and non-positive values.

Retry eligible request-execution I/O failures without a delay. Propagate
final response-body failures without replaying the request. Preserve
redirect protection, transfer-error reporting and commit-state-unknown
handling. Saturate oversized Retry-After conversions without overflow and
avoid echoing malformed OAuth token responses.

Document the transport policy and add regression coverage for retry rules,
key lifetime budgets, stable authentication, timeout precision and duration
boundaries.
Inject retry timing for deterministic tests while preserving Java retry behavior. Cover connection reuse, shorten slow socket tests, share timeout defaults and clarify legacy timeout naming and documentation.
Protect min/max calls from Windows SDK macros. Fix clang-tidy findings in transport code and retry tests while retaining libcurl native integer types and Java retry behavior.
Restore the upstream token-response parser and keep the targeted validation-error fix and regression coverage in PR apache#1079.
Honor the server-advertised idempotency window and recheck expiry before retrying. Freeze HTTP status retry decisions at final headers while allowing safe retries after partial-header resets.

Restrict Retry-After dates to HTTP-date formats, correct the storage credentials link, and add transport, configuration and concurrency regression coverage.
Use designated initializers for partial-header retry cases. Document and retain the long type required by CURLINFO_REQUEST_SIZE, including on Windows.
@zhjwpku
zhjwpku force-pushed the rest-http-client-transport branch from acf032f to e7364b0 Compare November 29, 2026 03:09

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants