Faraday: #get is not thread safe

Created on 26 Oct 2019  ·  4Comments  ·  Source: lostisland/faraday

https://github.com/lostisland/faraday/blob/d5eaa4ffe04b1cba00691b1cc2b2541e91093bf1/lib/faraday/adapter_registry.rb#L14-L26

Reading from a hash table while there are updates happening is not thread safe.

bug

All 4 comments

Ah I see what you mean, should we move the @lock.synchronise call into get instead?
I'm not sure we'd need it in set anymore after that?

You need it in both methods because you are reading and writing to @constants. You can't have synchronised access to the same hash table in any sitautions. Read only operations are not safe with simultaneous writes.

Alright, I merged a change to wrap the @constants in a synchronize.

Thanks, @ioquatix for the inspiration!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Lewiscowles1986 picture Lewiscowles1986  ·  4Comments

JasonBarnabe picture JasonBarnabe  ·  4Comments

aleksb86 picture aleksb86  ·  3Comments

ryanbyon picture ryanbyon  ·  3Comments

t3hk0d3 picture t3hk0d3  ·  3Comments