Repository navigation
Add onDiscard callback to Flows.fromPublisher - #419
Merged
Merged
Conversation
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.
Ports softwaremill/ox#529 to jox.
fromPublisherbuffers elements in a channel. Elements received from the publisher but never emitted were dropped, so nothing released them. This leaks elements that hold resources, such as Netty's reference-counted ByteBufs. The new overloadFlows.fromPublisher(publisher, onDiscard)passes each such element toonDiscard. Every received element is either emitted or discarded exactly once. The existing overload calls the new one with a no-op callback, so it works as before.Elements are discarded when:
take)Publisher errors still fail fast with the same exception (
ChannelErrorExceptioncaused by the publisher's error).onDiscardmay run on the publisher's threads and on the flow's thread at the same time, so it must be thread-safe. If it throws while buffered elements are being discarded, the rest are still discarded, and its exception is added as suppressed to the exception that ended the flow. A second subscription, or one that arrives after cancellation, is cancelled straight away.Also adds unit tests and a stress test, and updates
docs/flows.md. The otel modules andForkDecoratorTesthave formatting-only changes from running spotless.Open review findings
What the run's review left open, each with the reason recorded — including findings the fixer declined:
mvn -pl flows -am verifyreports 786 tests, 0 failures, BUILD SUCCESS.structured/pom.xml) — lint still failing after the fix turnstructured/pom.xml) — Environmental: the default JDK on this machine is 26, while the project targets Java 25 with preview features. With JDK 25 (mise install),mvn --batch-mode --update-snapshots verifyreports BUILD SUCCESS. No project change needed.structured/pom.xml) — Environmental: the default JDK on PATH is 26, and the project targets 25 on purpose. The build passes with JAVA_HOME set to the installed JDK 25 (mise): flows module verify gives 1088 tests, 0 failures, BUILD SUCCESS.structured/pom.xml) — Environmental. The project targets JDK 25 with preview features on purpose, and the reviewer's build ran on JDK 26. JDK 25 is installed (mise) and the build passes with JAVA_HOME pointing at it: the flows module verify (with -am) reported BUILD SUCCESS. Changing the configured release is out of scope.