Let ContextInternal#isRunningOnContext consider a duplicated context as its original context - #6315
Open
jnbdz wants to merge 1 commit into
Open
Conversation
…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.
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.
Motivation
ContextInternal#isRunningOnContext()compares the current context withthisby 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 (previouslycurrent() == thiswas simplyfalse). The javadoc states the rule.ContextTestcases:testIsRunningOnContext/testIsRunningOnContextWorker: original ↔ duplicate ↔ duplicate-of-duplicate all reporttruewhen running on any of them; a distinct context and its duplicate reportfalse; off-thread reportsfalse.testIsRunningOnContextFromEventBusHandler: the scenario from the issue — a consumer registered in a verticle, message delivered on a duplicate, the verticle context reportstrue.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 anEmitResultTaskfor what would have been an inline execution anyway.Verified locally:
ContextTest, the future/context/eventbus/deployment suites,Http1xTest,Http2Testand thevertx-core-java21-testsmodule (virtual threads) all pass.