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

Prefer Fiber#storage over copying thread locals #5173

Open
ioquatix opened this issue Nov 22, 2024 · 2 comments
Open

Prefer Fiber#storage over copying thread locals #5173

ioquatix opened this issue Nov 22, 2024 · 2 comments

Comments

@ioquatix
Copy link

I believe this code is extremely risky.

Thread.current.keys.each do |fiber_var_key|

@rmosolgo
Copy link
Owner

Hey, thanks for taking a look and sharing your concerns. The goal here is to retain compatibility with code that uses Thread.current.

I just started using Fiber[...] for library internals in #5034, and I'm open to migrating GraphQL-Ruby's usage to Fiber storage instead.

I'm also open to making this Thread.current behavior opt-in somehow (instead of default). But could you help me understand the risk you see with it now?

@ioquatix
Copy link
Author

ioquatix commented Nov 25, 2024

Risks:

  1. Context Misalignment: Thread-local variables are tied to a thread's specific operations, and copying them can lead to incorrect behavior in the new thread's context.

  2. Shared Mutable State Risks: Copying mutable thread-local variables can introduce race conditions and data corruption.

  3. Resource Mismanagement: Thread-local variables managing resources like database connections or file handles may be improperly shared or closed.

  4. Framework/Library Assumptions: Frameworks relying on Thread.current for logs, tracing, or error propagation may break or produce incorrect results.

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

No branches or pull requests

2 participants