Repository navigation
issue #636: fix flaky S3ObjectStorageDownloadToFileTest publisher (idempotent request(n)) - #637
Merged
eolivelli merged 1 commit intoMay 21, 2026
Conversation
The proxyClient helper's inline Subscription delivered the payload on every request(n) invocation. The Reactive Streams contract allows the subscriber to call request(n) any number of times; AsyncResponseTransformer .toFile() occasionally issued more than one request per subscription, which silently doubled the bytes written to disk and caused the rare "expected:<10> but was:<15>" flake in downloadToFileAppendsSubsequentBlocks. Extract the publisher into a static singleBufferPublisher helper that delivers onNext + onComplete at most once via an AtomicBoolean CAS, and treats cancel() as a terminal state. Add two deterministic regression tests that drive a hand-rolled Subscriber with multiple back-to-back request(n) calls and assert exactly one onNext. Verified by 50 successive full runs of the test class with no failures.
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.
Fixes #636.
Summary
The flake (
expected:<10> but was:<15>indownloadToFileAppendsSubsequentBlocks) was caused by a Reactive Streams contract violation in the test helper, not in production code. The inlineSubscriptioninsideproxyClientre-delivered the payload on everyrequest(n)invocation; the SDK'sAsyncResponseTransformer.toFile()is free to issue more than onerequest(n)per subscription (more often in the append-modedefaultCreateOrAppend()path), and any second request silently doubled the bytes written.The fix:
singleBufferPublisher(byte[])helper that deliversonNext+onCompleteat most once via anAtomicBoolean.compareAndSet.cancel()as a terminal state — flip the same flag so any post-cancelrequest(n)is a no-op.proxyClientnow usestransformer.onStream(singleBufferPublisher(payload));failingProxyClientis unchanged (it never creates a Subscription — it callstransformer.exceptionOccurred(error)directly).Production code (
S3ObjectStorage.downloadToFile) is unchanged.Regression tests
Two new deterministic tests pin the Reactive Streams contract:
requestIsIdempotentUnderMultipleRequestCalls— hand-rolledSubscribercallsrequest(1)/request(1)/request(Long.MAX_VALUE)synchronously insideonSubscribe; asserts exactly oneonNext, oneonComplete, zeroonError, and that the delivered bytes match the payload.requestAfterCancelIsNoOp—onSubscribecallscancel()thenrequest(1)/request(Long.MAX_VALUE); asserts neitheronNextnoronCompleteever fire.The original four tests in this file continue to pass.
Verification
S3ObjectStorageDownloadToFileTeston this branch: 50 / 50 green (pre-fix, the baredownloadToFileAppendsSubsequentBlockstest failed once over a handful of repeats).mvn -pl herddb-remote-file-service test): 495 / 495 green (was 493 / 493; +2 new tests).mvn -B spotless:check apache-rat:check spotbugs:check install -DskipTests -Pci): green.Test plan
herddb-remote-file-servicemodule suite green.🤖 Implemented by the
pr-workeragent.