httparty
httparty copied to clipboard
Thread Safe
Is this library thread safe?
If so, only by luck. There has been no intentional thread safe work, though I would be extremely open to pull requests toward this goal.
Any update here? We are using spacialdb/fcm gem in our JRuby app which internally uses HTTParty. We are facing issues related to multi threading there.
No update. I do not do much multi threaded stuff so I’m not the best person to work on this.
@prcongithub Hi! Could you be more specific please? Like what you you do and what's happening. That would help to identify and fix issues
@TheSmartnik I am using FCM which uses HTTParty internally. It modifies the base_uri to different values while making HTTP calls. With multi threaded applications, this doesn't work obviously. Code
@prcongithub thanks that's super helpful. I'll work on the problem. Unfortunately, I don't know if it's going to be fixed anytime soon.
Right now, I'd suggest to fork FCM and instead of using class method .base_uri for class, add it as argument for every request. It's a bit verbose, I know, but should fix the issue.
@TheSmartnik Will give this a try. I was also thinking of using Faraday in FCM instead of HTTParty. The use cases there are very limited and Faraday supports JRuby.
HTTParty stores a lot of state in class variables. If this changes over time, do not use these storage mechanisms. E.g. don't set oauth tokens in HTTParty.default_params.
I would say that HTTParty can be thread safe if used carefully, but does not enforce thread-safe patterns whatsoever.