Skip to content
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

Close open connections from parent after fork #16953

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,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 @@ -330,6 +331,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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's worded as well as it can be. Nice job!

#
# 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

# Overriding queue_name as now some queue names can be
# arrays of names for some workers not just a singular name.
# We use JSON.parse as the array of names is stored as a string.
Expand Down