Core: Treat a lost REST commit response as an unknown commit state #18903
Nice, a lost response really should go through the same reconciliation as a 5xx, and keeping it to commit requests addresses the concern from #6778.
1. In RESTTableOperations.commitRequest (around L261), ConnectException is the only "never sent" case. With HttpClient 5, ConnectTimeoutException extends SocketTimeoutException, and it also covers waiting for a connection from the pool, so a connect or lease timeout would now be reported as unknown even though nothing was sent. UnknownHostException and an SSL handshake failure are the same. Could those be excluded too, or the check flipped to the cases that can happen after the request is written?
2. For create and replace transactions commit() only reconciles SIMPLE updates, so a lost response there now surfaces as CommitStateUnknownException instead of RESTException. Probably the right call, but worth a line in the description since callers that retried on RESTException will now stop.
3. A test with ConnectTimeoutException next to testCommitThatCannotConnectIsNotCommitStateUnknown would pin down point 1.
Thanks @developer-rpai , good catches.
1. Agreed. ConnectTimeoutException is a SocketTimeoutException, so it was being reported as unknown. One correction: in HttpClient 5.6 waiting for a pooled connection throws ConnectionRequestTimeoutException (an InterruptedIOException), not ConnectTimeoutException. Both are now treated as never sent, along with UnknownHostException, NoRouteToHostException and SSLHandshakeException. I kept the default as unknown rather than flipping to an allow-list of after-send failures. Missing a pre-send case only reports a harmless failure as unknown, which can leave orphan files. Missing a post-send case (a reset, a broken pipe, a TLS error mid-stream, a proxy closing the connection) would bring this bug back. The pre-send list is the shorter and better-defined one.
2. Added to the description.
3. Done: testCommitThatWasNeverSentIsNotCommitStateUnknown is parameterized over all six, and testLostCommitResponseIsCommitStateUnknown over a read timeout, no response and a connection reset. The pre-send test calls commitRequest directly, because Tasks treats a ConnectionRequestTimeoutException as an interruption and sets the caller's interrupt flag. That's existing behaviour, noted in the description.
4. Strictly, the two HttpClient 5 checks belong in HTTPClient, so that each RESTClient implementation can decide this for itself. That felt like too wide a change for this fix, so I've left them in RESTTableOperations. Other clients never throw those two types, so the checks are simply never triggered for them, and their connect timeouts fall back to the safe default of unknown. Happy to move them if you'd prefer.
Thanks, this looks good. Keeping unknown as the default makes sense to me, a missed pre send case only costs an orphan file while a missed post send case brings the bug back. Fine with leaving the two HttpClient checks in RESTTableOperations for now, moving them into HTTPClient feels like its own follow up. LGTM.
doesn't this only inspect the last http attempt? if a keyed post reaches the server, loses the response, and then fails to connect on an automatic retry, the final connection error makes failedBeforeSending return true and throws RESTException instead of CommitStateUnknownException. could we track attempt history on the request's HttpContext and pass it from HTTPClient (or drop !failedBeforeSending as a fallback), and add a real HTTPClient test for a lost keyed-post reply followed by connection refusal?
overall the direction makes sense, i left one comment. main concern is that an http retry can mask an earlier attempt that already reached the server.
@timothyw553 - Good catch, that case wasn't handled. The same applied to a keyed POST that got a 503, was retried, and then had the connection refused.
I've moved the tracking into HTTPClient as you suggested. It now uses an HttpClient interceptor that tracks how each attempt ended, so if any attempt may have reached the server, the final error says so, whatever happened on the last try. RESTTableOperations then only has to turn that into a CommitStateUnknownException, without digging through exception causes.
I added real HTTPClient tests for a lost keyed-POST reply followed by connection refusal, a 503 followed by connection refusal, a read timeout, a malformed response, and a refused first attempt (which stays an ordinary failure).
@developer-rpai this also moves the "never sent" checks into HTTPClient, including the two HttpClient 5 ones. That's the follow-up we discussed, but it made more sense to do it here given @timothyw553's suggestion. It's a bit different from the version you approved, so worth another look if you have time.
developer-rpai
gardenia
When a REST commit request fails after it may have reached the server (no response, a connection reset, a read timeout),
HTTPClientreports a plainRESTException, so an applied commit is treated as failed and a retry can apply it twice.HTTPClientnow tracks every attempt, including automatic retries, and throwsUnknownRequestOutcomeExceptionwhen any attempt may have been received. That is still aRESTException, so other callers are unaffected, which was the concern in #6778; only table and multi-table commits turn it intoCommitStateUnknownException, so snapshot-add-only commits get the existing 5xx reconciliation. Create and replace transactions (CTAS/RTAS) aren't reconciled, so a lost response to them now raisesCommitStateUnknownExceptioninstead ofRESTException.Fixes #18902
Test plan:
RESTException, since nothing was sent.CommitStateUnknownException.---
AI Disclosure