-
Notifications
You must be signed in to change notification settings - Fork 550
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
Is mysql2 thread-safe? #385
Comments
Sort of yes and no, and nothing that's much different than any other mysql client library. It is safe to access mysql2 objects across threads, but there's no locking inside mysql2, and even so, that's secondary to the fact that you cannot do more than one thing at a time with an underlying mysql client socket. If you need to run queries simultaneously in two different threads, then you should create two separate client objects. Each one will own its own database connection. This is not any different than if you had a single thread and tried to run several queries and stream back the results in an intermingled fashion -- you can't do that. Each result object returned from a client.query will be tied to that Client instance, and that in turn is tied to a mysql connection, which is a stateful protocol so must complete one thing before moving on to another. @brianmario ought we to put together some explanation of this relationship for the README? I'm happy to write it up when I have some time soon. |
I see. So the standard usage of rails with activerecord + puma + mysql2 has no danger? |
@thehappycoder yeah exactly. Things should work fine, but please let us know if not ;) |
Please include that info in the documentation.
The text was updated successfully, but these errors were encountered: