Thanks for the feedback, given that, I think the MavenSession should then be some kind of immutable object and all "setters" must actually create a new object with updated values, that would make it clear and (thread-) safe.

Even though this won't solve my issue as I try to implement a WorkspaceReader and the only option seems to make this a SessionScoped component as here[1].

The in public File findArtifact( Artifact artifact ) I need the current project (if any) e.g. if this is from a request to resolve a project (custom) dependency.

And here the issue arise as BuildListCalculator (for good reasons) clone the session I always get a false current project ,as the "rootSession" never knows a about the changed current project and this is what I'm actually get injected.

I also have created a PR[3] that should be still support cloning the session but won't force BuildListCalculator to clone the session.

The only other option seems to have some side-band communication with
BuilderCommon.attachToThread(...) but as this is maven internal this does not sound very good to attach there...


[1] https://github.com/apache/maven/blob/master/maven-core/src/main/java/org/apache/maven/ReactorReader.java [2] https://github.com/apache/maven/blob/master/maven-core/src/main/java/org/apache/maven/lifecycle/internal/BuildListCalculator.java#L64
[3] https://github.com/apache/maven/pull/666



Am 29.01.22 um 12:59 schrieb Romain Manni-Bucau:
Hi Christoph,

There is no real doc but a few things make it hard:

1. Plugin expect the injected session to stay so threadlocal dont work in
general and inheritedthreadlocal leak being an issue in several env like
mvnd
2. It should support concurrency

There was some hack done but if you still hit some issue i guess a kind of
view injection will be needed per mojo instead of hacking the session
itself directly ensuring the session is thread safe but the mojo also stick
to its view/project instance.

Le sam. 29 janv. 2022 à 11:35, Christoph Läubrich <[email protected]> a
écrit :

I'm currently having some issues in a plugin that access the
MavenSession with different threads.

I can't find that MavenSession is intended for concurrent access so I
wonder if in general it should support that case or if it is expected to
clone the session?

But clone() does not make a deep copy so there are still room for
problems (e.g. modifications might not write through to the original
session) so I wonder if there is any normative document telling how to
handle a session correctly?

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to