-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Unexpected local context data behavior change for duplicated context #5505
Comments
@ben1222 can you instead use your own As said in the issue that changes this behaviour, semantic was not clearly defined and we try to make it well defined instead with context local SPI. perhaps also we could improve the duplication and handle map/concurrent map with a copy and that would help your case to be solved ? |
Using A few options to keep backward compatibility may be:
See this section: Advanced Vert.x Guide - Contexts and tracing Although this semantic is not explicitly defined, I'm not sure how many people have similar impression as me... I agree that the semantic can be better defined with context local SPI, but it looks like still need some polish (or are you already planning to do something?):
I'm not sure if I understand this question correctly... if you are saying to do a deep copy, then no, it will not help in our case. |
@ben1222 one reason is that the putLocal/getLocal should never have been made public API as they actually target internal vertx usage, hence there is lot of confusion around it. if we revert the usage, we need to break it still in 5.0 :-( this behavior is actually needed by gRPC context storage to works correctly (and it makes sense) let me know how 2. works for you, as this is the option that gives control to the owner of the local. Yes local are like thread locals but they are attached to a flow of execution supported by multiple threads |
It is a great feature and is useful not only for internal vertx, at least it helped us a lot.
May I ask why it will still break in 5.0? Is it because of the gRPC context storage?
I'm not familiar with gRPC so please correct me if I'm wrong:
With this, we may just switch it back to old behavior (no copy on context duplication). |
As a side note : in Vert.x 5 getLocal/putLocal have been moved to ContextInternal and we consider instead people should use context local, yet they are still available with a cast. Since you are a user of this API, what is your opinion on this? do you find it acceptable ? See https://vertx.io/docs/guides/vertx-5-migration-guide/#_context_local_storage_removal, we should document I think the new alternative of |
FYI : #5506 |
Version
4.5.12
Context
Before 4.5.11, when duplicating a duplicated context, it always have empty local context data at beginning, just like what the Javadoc says.
However, in 4.5.12, due to the changes in #5441, the local context data is copied.
There are 2 concerns here:
It may break existing code that rely on empty local context on duplicating
DuplicatedContext
In our use case, we put a map in the local context data (using
getLocal()
/putLocal()
, we used it beforeContextLocal
was introduced) to track some data.We were expecting duplicating
DuplicatedContext
also starts with empty local context data, just like duplicatingContextImpl
, so that our map can track only what’s run on the current duplicated context.However, after the behavior change in 4.5.12, since the local context data is copied to new
DuplicatedContext
when duplicating fromDuplicatedContext
, we got many duplicated contexts referencing same map instance and messed things up.One option for us could be clearing the local context data on any places that may produce duplicated context (e.g., every message consumer), but it requires lots of changes, and having unnecessary overhead of copying and then clearing local context data.
Another option for us is to move our map to a separate
ContextLocal
, and customize a duplicator to always return null. (a minor problem is that if such local data is only used in a small part of contexts, the overhead of reserving one more slot for every context/duplicated context may not worth it)Why changing the behavior of existing
getLocal()
/putLocal()
use cases?Can the duplicator of
ContextInternal.LOCAL_MAP
be changed to always return null?Or at least support configuring the default behavior of duplicating context to not copying?
Inconsistent behavior between duplicating
ContextImpl
andDuplicatedContext
Before 4.5.12, the behavior was consistent – it always create a
DuplicatedContext
with no local context data.In 4.5.12, duplicating
ContextImpl
will not copy the local context data inContextImpl
intoDuplicatedContext
, while duplicatingDuplicatedContext
will copy the local context data to the newDuplicatedContext
.This is really confusing me... is it by design to not allow the customized duplicator of
ContextLocal
to not work when duplicating fromContextImpl
?Do you have a reproducer?
Tried to create a unit test to illustrate one kind of use cases:
In 4.5.11, it passes, and in 4.5.12, it fails with:
The text was updated successfully, but these errors were encountered: