Skip to content

Fix lazy attribute method definitiont to be thread safe - #53890

Merged
byroot merged 1 commit into
rails:mainfrom
byroot:fix-lazy-attr-method-definition-thread-safety
Dec 10, 2024
Merged

byroot merged 1 commit into
rails:mainfrom
byroot:fix-lazy-attr-method-definition-thread-safety

Conversation

@byroot

@byroot byroot commented Dec 10, 2024

Copy link
Copy Markdown
Member

Fix: #53667
Followup: #50594

We can't safely check if attribute methods were generated or not as we may be in a race with another thread. As such we must always consider that maybe the mehtod was just generated.

Fix: rails#53667
Followup: rails#50594

We can't safely check if attribute methods were generated or not
as we may be in a race with another thread. As such we must always
consider that maybe the mehtod was just generated.
@byroot
byroot force-pushed the fix-lazy-attr-method-definition-thread-safety branch from 3e1e07d to b458919 Compare December 10, 2024 10:23
@byroot
byroot merged commit ae69680 into rails:main Dec 10, 2024
@byroot
byroot deleted the fix-lazy-attr-method-definition-thread-safety branch December 10, 2024 11:11
byroot added a commit that referenced this pull request Dec 10, 2024
…-thread-safety

Fix lazy attribute method definitiont to be thread safe
byroot added a commit that referenced this pull request Dec 10, 2024
…-thread-safety

Fix lazy attribute method definitiont to be thread safe
byroot added a commit that referenced this pull request Dec 10, 2024
…-thread-safety

Fix lazy attribute method definitiont to be thread safe
@byroot

byroot commented Dec 10, 2024

Copy link
Copy Markdown
Member Author

Backported to 8.0, 7.2 and 7.1

@Laykou

Laykou commented Dec 10, 2024

Copy link
Copy Markdown

Thank you. How is it with the releases? When do you think this could be released? As this multi-thread issue creates a blocker for upgrading and deploying version beyond 7.1.3.4

@byroot

byroot commented Dec 10, 2024

Copy link
Copy Markdown
Member Author

Patch releases aren't pre-programmed so I can't answer your question.

If you are in a rush, you can point your gemfile to the git repository.

skipkayhil pushed a commit to hammadxcm/rails that referenced this pull request Aug 13, 2026
…tributes

Guard `public_instance_method` call with `public_method_defined?` to
avoid raising and rescuing `NameError` for attributes not backed by
real columns (e.g. `SELECT 42 AS virtual_attr`).

The `NameError` exception allocation + backtrace capture costs ~9μs per
call, causing a ~3x regression introduced in rails#53890. This restores
performance by using a cheap boolean check on the common path.

Fixes rails#57183.
skipkayhil pushed a commit to hammadxcm/rails that referenced this pull request Aug 13, 2026
…tributes

Guard `public_instance_method` call with `public_method_defined?` to
avoid raising and rescuing `NameError` for attributes not backed by
real columns (e.g. `SELECT 42 AS virtual_attr`).

The `NameError` exception allocation + backtrace capture costs ~9μs per
call, causing a ~3x regression introduced in rails#53890. This restores
performance by using a cheap boolean check on the common path.

Fixes rails#57183.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Activerecord's method_missing method is not thread-safe

2 participants