httparty icon indicating copy to clipboard operation
httparty copied to clipboard

Thread Safe

Open agerber23 opened this issue 8 years ago • 8 comments
trafficstars

Is this library thread safe?

agerber23 avatar Feb 01 '17 17:02 agerber23

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.

jnunemaker avatar Feb 02 '17 15:02 jnunemaker

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.

prcongithub avatar Jan 28 '19 10:01 prcongithub

No update. I do not do much multi threaded stuff so I’m not the best person to work on this.

jnunemaker avatar Jan 28 '19 13:01 jnunemaker

@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 avatar Jan 28 '19 14:01 TheSmartnik

@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 avatar Jan 29 '19 03:01 prcongithub

@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 avatar Feb 01 '19 09:02 TheSmartnik

@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.

prcongithub avatar Feb 01 '19 13:02 prcongithub

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.

jakeonfire avatar Dec 24 '19 03:12 jakeonfire