Skip to content

Fix ManualTime.expectNoMessageFor async delivery race#3329

Open
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/manual-time-expect-no-message-race
Open

Fix ManualTime.expectNoMessageFor async delivery race#3329
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/manual-time-expect-no-message-race

Conversation

@He-Pin

@He-Pin He-Pin commented Jul 11, 2026

Copy link
Copy Markdown
Member

Motivation

ManualTime.expectNoMessageFor advanced manual time and then polled each probe with a zero timeout. Scheduler tasks run synchronously, but actor mailbox processing and probe delivery remain asynchronous, so the assertion could pass before an unexpected message reached the probe.

Modification

Use each probe’s configured no-message timeout in both the Scala and Java DSLs. Document the post-advance observation window and add deterministic regression tests using a blocked single-thread dispatcher for both APIs.

Result

Unexpected messages triggered during a manual time advance are observed reliably instead of being missed by a non-blocking poll.

References

Fixes #3235

Motivation:
ManualTime.expectNoMessageFor used a zero-timeout probe poll after advancing manual time, allowing asynchronously dispatched messages to be missed.

Modification:
Use the configured no-message timeout in both Scala and Java DSLs, document the behavior, and add deterministic regression coverage for delayed delivery.

Result:
ManualTime.expectNoMessageFor now fails when a message triggered during the time advance reaches a probe asynchronously.

Tests:
- sbt "+actor-testkit-typed / Test / testOnly org.apache.pekko.actor.testkit.typed.scaladsl.ManualTimeSpec" (passed on Scala 2.13.18 and 3.3.8)
- sbt "actor-testkit-typed / Test / test" (175 total, 174 passed, 1 ignored)
- sbt "+headerCheckAll" (passed)
- sbt checkCodeStyle (passed)
- native scalafmt diff and new-file checks (passed)
- Qoder stdout review (no must-fix findings)
- sbt sortImports (environment failure: Scalafix/Scalameta NoSuchMethodError)
- sbt validatePullRequest (interrupted at user request)

References:
Fixes apache#3235
@He-Pin He-Pin added this to the 2.0.0-M4 milestone Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ManualTime.expectNoMessageFor uses Duration.Zero causing race condition

1 participant