From 7b21b23bb41848ff59e59045f7f1fb975b3b9e66 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Tue, 27 Aug 2019 11:36:44 -0700 Subject: [PATCH] Detect fork and do not reuse forked connections in drb This associates each DRbConn with a pid, and if the pid changes, it closes any DRbConns in the pool with a pid that no longer matches. This fixes DRb servers from sending messages intended for one client to another client after forking. Fixes [Bug #2718] Fixes [Bug #14471] --- lib/drb/drb.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb index caffd5df25..bff83a09c4 100644 --- a/lib/drb/drb.rb +++ b/lib/drb/drb.rb @@ -1209,15 +1209,20 @@ class DRbConn def self.open(remote_uri) # :nodoc: begin conn = nil + pid = $$ @mutex.synchronize do #FIXME new_pool = [] @pool.each do |c| - if conn.nil? and c.uri == remote_uri - conn = c if c.alive? + if c.pid == pid + if conn.nil? and c.uri == remote_uri + conn = c if c.alive? + else + new_pool.push c + end else - new_pool.push c + c.close end end @pool = new_pool @@ -1243,9 +1248,11 @@ def self.open(remote_uri) # :nodoc: def initialize(remote_uri) # :nodoc: @uri = remote_uri + @pid = $$ @protocol = DRbProtocol.open(remote_uri, DRb.config) end attr_reader :uri # :nodoc: + attr_reader :pid # :nodoc: def send_message(ref, msg_id, arg, block) # :nodoc: @protocol.send_request(ref, msg_id, arg, block) -- 2.22.0