Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add thread-safety to TypeAdaptor method adaptation #5621

Merged
merged 1 commit into from
Jan 22, 2024

Conversation

MartinWitt
Copy link
Collaborator

@MartinWitt MartinWitt commented Jan 17, 2024

This should fix #5619, but I am not sure if locking on a method parameter is more elegant than calling clone.

@SirYwell
Copy link
Collaborator

I think one main issue is that other accesses to the method body that don't go through this lock won't care and might see invalid state. But @I-Al-Istannen surely can weigh in on this.

@I-Al-Istannen
Copy link
Collaborator

Yea, this is not quite enough. We could add a flag to the adapt method that defines whether we are only interested in the signature 🤔

When checking whether a method overrides another, we need to adapt both
methods to a common ground.
In an early version this required cloning the entire method, including
its body, to perform the adaption. PR #4862 fixed this by nulling the
body before cloning the method and then restoring it afterwards. This
operation is not thread safe, as it may write concurrently and also
modifies what other parallel threads might see when traversing the
model.

This patch now introduces a private override specifying whether we are
only interested in the signature. If that is the case, we explicitly
construct a new method using the factory instead of cloning the
original.

Closes: #5619
Copy link
Collaborator

@I-Al-Istannen I-Al-Istannen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took over this poor PR, so my review should not count much :)

Copy link
Collaborator

@SirYwell SirYwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good.

@MartinWitt
Copy link
Collaborator Author

@SirYwell feel free to merge

@SirYwell SirYwell merged commit 7121a4c into master Jan 22, 2024
11 checks passed
@SirYwell SirYwell deleted the fix/issue5619 branch January 22, 2024 19:04
@monperrus
Copy link
Collaborator

Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants