-
Notifications
You must be signed in to change notification settings - Fork 49
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
Thread safety problems #71
Comments
`Net::HTTP`, in Ruby's standard library, is not threadsafe. The issue is easy to sidestep by creating a new `Net::HTTP` object for every lookup. The overhead of creating a new object compared to the network lookup call is trivial.
@sb8244 great find! I have a fix coming. The issue is really that the http client is cached, so the same client is used for every lookup. Using |
`Net::HTTP`, in Ruby's standard library, is not threadsafe. The issue is easy to sidestep by creating a new `Net::HTTP` object for every lookup. The overhead of creating a new object compared to the network lookup call is trivial.
`Net::HTTP`, in Ruby's standard library, is not threadsafe. The issue is easy to sidestep by creating a new `Net::HTTP` object for every lookup. The overhead of creating a new object compared to the network lookup call is trivial.
`Net::HTTP`, in Ruby's standard library, is not thread-safe. The issue is easy to sidestep by creating a new `Net::HTTP` object for every lookup. The overhead of creating a new object compared to the network lookup call is trivial.
I'll target the fix for a |
👏 nice! For informational sake: what type of problems can arise from using Thread.current in this situation? |
@sb8244 The possible problem arises because While this is not a problem in most use-cases for the gem, it certainly arises in tests and is a possible problem if anyone has a custom http client/lookup. An example would be a custom lookup client that falls through from one client to another in the case of failure (for example if the 3rd party service is not responding). Essentially the issue is that a single HTTP client (w/ configured credentials and URLs) could be used by two separate lookups so you could end up sending Geonames formatted queries to Google. |
Appreciate the explanation! Thanks for your time in maintaining this gem.
On Mon, Jan 30, 2017 at 6:25 PM Pan Thomakos ***@***.***> wrote:
@sb8244 <https://github.com/sb8244> The possible problem arises because
Thread.current is global in the current thread. That means that two
separate lookups (ex: Timezone::Lookup::Geonames and
Timezone::Lookup::Google) could end up using the same cached HTTP client.
While this is not a problem in most use-cases for the gem, it certainly
arises in tests and is a possible problem if anyone has a custom http
client/lookup. An example would be a custom lookup client that falls
through from one client to another in the case of failure (for example if
the 3rd party service is not responding).
Essentially the issue is that a single HTTP client (w/ configured
credentials and URLs) could be used by two separate lookups so you could
end up sending Geonames formatted queries to Google.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#71 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABLLK6JxRayqNbPuvVroA-Ue6eFkh9WVks5rXnFlgaJpZM4LstKF>
.
--
Steve Bussey • SalesLoft
• Software Engineer
| e. [email protected] | w. http://salesloft.com
<http://salesloft.com/?v=1&utm_expid=76406993-1.E5ncJhwyTAW9uGaR1WdBTA.1?utm_source=email-signature>
| s. 3405 Piedmont Rd NE, Atlanta, GA 30305
<https://www.facebook.com/SalesLoft> <https://twitter.com/SalesLoft>
<https://www.linkedin.com/company/salesloft>
<http://salesloft.com/prospector/#video> <http://blog.salesloft.com/blog/>
|
Hello, I wanted to bring up a problem that I've recently found. The stock implementation of NetHTTPClient is not thread safe with the global lookup objects. I identified this in an older gem version, but confirmed it is also present in the latest master version.
The problem's root is demonstrated here, by the lack of thread safety to the same http instance:
You will get a variety of errors (randomly) if you run this locally:
Here is the reproduction with Timezone gem (master)
This will provide a variety of errors as well:
Proposed Fix
I'm locally going to use a wrapper around NetHTTPClient that provides thread safety. Here's a rough working version of it:
The text was updated successfully, but these errors were encountered: