On Mon, 20 Jan 2025 17:55:49 GMT, Daniel Fuchs <dfu...@openjdk.org> wrote:
> There's a subtle race condition in AggregatePublisher.AggregateSubscription. > The AggregatePublisher will subscribe to downstream publishers in turn, > subscribing to the next publisher when the previous publisher onComplete() > has been called. > > The request() method passed to the upstream subscriber detects that all > subscribers have completed if the current downstream publisher is null and > the queue of publisher yet to subscribe to is empty. > > The event loop is responsible for subscribing to the next publisher, and does > so by polling the queue and assigning the returned value to this.publisher, > and then subscribe to that publisher. However, when subscribing to the last > publisher in the queue, there is a small time window where the queue can be > observed to be empty, before this.publisher is assigned. > > The fix adds synchronization to make sure a consistent state is observed when > it matters. Typically - setting `this.publisher` or taking a snapshot of a > publisher and its subscription, should be done within synchronized. This pull request has now been integrated. Changeset: b720517c Author: Daniel Fuchs <dfu...@openjdk.org> URL: https://git.openjdk.org/jdk/commit/b720517cb33c2119ec6ed85504bce321de748228 Stats: 125 lines in 2 files changed: 81 ins; 13 del; 31 mod 8348108: Race condition in AggregatePublisher.AggregateSubscription Reviewed-by: jpai ------------- PR: https://git.openjdk.org/jdk/pull/23204