Skip to content

Mono.awaitSingleOrNull does not await completion #3487

@dkhalanskyjb

Description

@dkhalanskyjb

(NB: checked the other reactive integrations, and none of them have this problem)

Mono.awaitSingleOrNull has a subtle bug: it will resume with the provided value before onComplete has happened. This leads to concurrency issues when a Publisher emits a value before actually finishing the work.

To fix such issues, we introduced awaitSingleOrNull in the past (#1993), which checked that there was, in fact, just a single element. As a side effect, it ensured that onComplete was called.

We deprecated awaitSingleOrNull for unrelated reasons and wrote a specialized implementation Mono.awaitSingleOrNull. There, this desired property was lost. We need to restore it.

The impact in a typical case where such issue does not arise should be negligible, because, as the Mono documentation states,

Most Mono implementations are expected to immediately call Subscriber.onComplete() after having called Subscriber#onNext(T).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions