Skip to content

Let ContextInternal#isRunningOnContext consider a duplicated context as its original context - #6315

Open
jnbdz wants to merge 1 commit into
eclipse-vertx:masterfrom
SiteNetSoft:issue-4576-running-on-context
Open

Let ContextInternal#isRunningOnContext consider a duplicated context as its original context#6315
jnbdz wants to merge 1 commit into
eclipse-vertx:masterfrom
SiteNetSoft:issue-4576-running-on-context

Conversation

@jnbdz

@jnbdz jnbdz commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Motivation

ContextInternal#isRunningOnContext() compares the current context with this by identity. When code runs on a duplicated context — for instance an event-bus consumer handler deployed in a verticle, since messages are delivered on a duplicate of the consumer context — the verticle context reports that it is not running on the context, although the duplicate shares the exact same concurrency model (same event loop / same worker task queue).

Fixes #4576, following the direction discussed there (comparison with the delegate context).

Changes

  • isRunningOnContext() now compares the unwrapped contexts: a context, its duplicates and duplicates of duplicates are considered the same context. A null current context is guarded (previously current() == this was simply false). The javadoc states the rule.
  • New ContextTest cases:
    • testIsRunningOnContext / testIsRunningOnContextWorker: original ↔ duplicate ↔ duplicate-of-duplicate all report true when running on any of them; a distinct context and its duplicate report false; off-thread reports false.
    • testIsRunningOnContextFromEventBusHandler: the scenario from the issue — a consumer registered in a verticle, message delivered on a duplicate, the verticle context reports true.

Impact

The only internal caller is FutureBase#emitResult. Both of its branches dispatch the listener with the future's own context (beginDispatch/endDispatch), so its observable behaviour is unchanged; when the current thread is on a sibling duplicate it now avoids scheduling an EmitResultTask for what would have been an inline execution anyway.

Verified locally: ContextTest, the future/context/eventbus/deployment suites, Http1xTest, Http2Test and the vertx-core-java21-tests module (virtual threads) all pass.

…as its original context

Motivation:

ContextInternal#isRunningOnContext compares the current context with this
context by identity. When code runs on a duplicated context, e.g. an
event-bus consumer handler in a verticle, the verticle context reports that
it is not running on the context although both share the same concurrency
model. Fixes eclipse-vertx#4576.

Changes:

Compare the unwrapped contexts, so that a context, its duplicates and the
context it duplicates are considered the same context. Guard against a null
current context. Document the rule in the javadoc.

Add ContextTest cases for event-loop and worker contexts covering the
original, duplicates and duplicates of duplicates, a distinct context and
its duplicate, off-thread invocation, and the event-bus handler scenario
reported in the issue.
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.

Should ContextInternal#isRunningOnContext cognize DuplicatedContext?

1 participant