lib/typhoeus/pool.rb in typhoeus-0.7.0 vs lib/typhoeus/pool.rb in typhoeus-0.7.1

- old
+ new

@@ -7,10 +7,11 @@ # because creating them is expensive. # # @api private module Pool @mutex = Mutex.new + @pid = Process.pid # Releases easy into the pool. The easy handle is # reset before it gets back in. # # @example Release easy. @@ -25,10 +26,20 @@ # @example Return easy. # Typhoeus::Pool.get # # @return [ Ethon::Easy ] The easy. def self.get - @mutex.synchronize { easies.pop } || Ethon::Easy.new + @mutex.synchronize do + if @pid == Process.pid + easies.pop + else + # Process has forked. Clear all easies to avoid sockets being + # shared between processes. + @pid = Process.pid + easies.clear + nil + end + end || Ethon::Easy.new end # Clear the pool def self.clear @mutex.synchronize { easies.clear }