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

Enhance Thread and Fiber Safety in ActiveRecordExaminer #353

Closed
wants to merge 8 commits into from
Closed

Enhance Thread and Fiber Safety in ActiveRecordExaminer #353

wants to merge 8 commits into from

Conversation

coderberry
Copy link

@coderberry coderberry commented Mar 6, 2024

Attempt to fix #349

This PR fixes this issue by wrapping the Fiber that is accessing the connection pool with a temporary "root" Fiber. Once the query has completed, the fiber will be terminated and the connection will be returned to the pool.

This PR is at a state where a fix can be applied and tested, but the implemented fix is not correct.

@coderberry
Copy link
Author

@swrobel Would you mind reviewing this PR and provide any feedback or insights? I learned a LOT from following you around in GitHub issues and discussions.

Copy link
Contributor

@dividedmind dividedmind left a comment

Choose a reason for hiding this comment

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

The PR summary isn't informative; it reads as if it's machine-generated, it doesn't explain why the changes are necessary or correct. In fact I suspect that they're incorrect or at least inefficient. Could you please explain? I don't understand how that does anything to "improve fiber and thread safety" or indeed what problem is being solved.

EDIT: Sorry, I just read the linked issue, I see the problem. Still, with thread isolation, it seems the change cause a thread to be launched and two connections checked out from the pool for every query or in_transaction?; these threads then proceed to be zombies because they're never joined. This doesn't seem right, especially if there's already a thread being launched by ActiveSupport. Even in the fiber case, some tests would be useful to illustrate.

lib/appmap/handler/rails/sql_handler.rb Outdated Show resolved Hide resolved
lib/appmap/handler/rails/sql_handler.rb Outdated Show resolved Hide resolved
@coderberry
Copy link
Author

coderberry commented Mar 6, 2024

@dividedmind thank you for your feedback. I forgot to flag this PR as a draft. Tests and a better description are coming 🙌🏻

And yes, the description was created by ChatGPT. I planned on updating it, along with adding tests and inline docs before it's ready for final review. I wanted to make this code available early for any feedback such as yours. 👍

@coderberry coderberry marked this pull request as draft March 6, 2024 15:37
.nvmrc Outdated Show resolved Hide resolved
ActiveRecord::Base.connection_pool.with_connection { yield }
end.resume
else
ActiveRecord::Base.connection_pool.with_connection { |conn| block.call(conn) }
Copy link
Contributor

Choose a reason for hiding this comment

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

I see no block in this context.

@coderberry coderberry closed this Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add compatibility with Fiber-safe ConnectionPool in Rails 7.1
3 participants