her icon indicating copy to clipboard operation
her copied to clipboard

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

Open mltsy opened this issue 8 years ago • 1 comments

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.

mltsy avatar Nov 30 '17 18:11 mltsy

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 :-).

edtjones avatar Nov 30 '17 19:11 edtjones