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

API/connection is not thread safe... by default #475

Open
mltsy opened this issue Nov 30, 2017 · 1 comment
Open

API/connection is not thread safe... by default #475

mltsy opened this issue Nov 30, 2017 · 1 comment

Comments

@mltsy
Copy link

mltsy commented Nov 30, 2017

It may just be a matter of documentation to address this, but the way the documentation recommends setting Her up (with a single instance of Her::API) is not thread-safe because it uses a class instance variable, default_api, to store the instance created, and that instance's connection is shared for all threads (not safe) :)

We should either add some documentation about how to use this in a thread-safe way (i.e. create a new instance of Her::API for each thread using Thread.current[:my_api] = API.new(...)), or do that for the user automatically by storing @default_api as a thread-local variable, and regenerate it for each thread automatically rather than using a class instance variable.

@edtjones
Copy link
Collaborator

Thanks Joe - we should probably refactor so it’s threadsafe really. If you wanted to have a crack at putting a PR together that would be brilliant. Even just a PR for the readme to include some notes on the workaround would be appreciated :-).

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