Skip to content

Commit

Permalink
Merge pull request #16953 from agrare/bz_1385038_fix_shared_drb_conne…
Browse files Browse the repository at this point in the history
…ctions_after_fork

Close open connections from parent after fork
(cherry picked from commit b6062af)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1481378
  • Loading branch information
jrafanie authored and simaishi committed Feb 6, 2018
1 parent 478b32a commit 3553fe8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/models/miq_worker.rb
Expand Up @@ -316,6 +316,7 @@ def self.before_fork
def self.after_fork
close_pg_sockets_inherited_from_parent
DRb.stop_service
close_drb_pool_connections
renice(Process.pid)
end

Expand All @@ -332,6 +333,23 @@ def self.close_pg_sockets_inherited_from_parent
end
end

# Close all open DRb connections so that connections in the parent's memory space
# which is shared due to forking the child process do not pollute the child's DRb
# connection pool. This can lead to errors when the children connect to a server
# and get an incorrect response back.
#
# ref: https://bugs.ruby-lang.org/issues/2718
def self.close_drb_pool_connections
require 'drb'

# HACK: DRb doesn't provide an interface to close open pool connections.
#
# Once that is added this should be replaced.
DRb::DRbConn.instance_variable_get(:@mutex).synchronize do
DRb::DRbConn.instance_variable_get(:@pool).each(&:close)
end
end

def start_runner
self.class.before_fork
pid = fork(:cow_friendly => true) do
Expand Down

0 comments on commit 3553fe8

Please sign in to comment.