Question

I've read this post about how inherently unsafe ruby's timeout method is, but I it looks like JRuby has natively implemented the Timeout class and I was wondering if those issues are still relevant in JRuby 1.7? From what I can decipher from the source, it looks like there is a reusable thread pool being used so that should take out a lot of the performance issues of launching a new thread for every single use, but I was wondering about the safety issues, specifically for when its being used extensively in Net::HTTP. Is there some kind of mutex locking going on to solve those safety problems now? (sorry i don't know java well enough to tell definitively from the source).

Long question short: is Timeout::timeout, and by extention Net::HTTP which uses it a ton, safe and performant to use in JRuby 1.7?

Was it helpful?

Solution

Yup, still unsafe in general:

No timeout library can solve this problem unless they are able to guarantee they'll never fire within any ensure blocks

Although, when used in Net::HTTP around pieces of code that don't have any ensure blocks, it should probably be fine I'm guessing. (Though they should really be using nonblocking io and select)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top