DRb mixing up function return values between PIDs after fork()
This is likely a duplicate of https://bugs.ruby-lang.org/issues/2718, although the Backport191 project in redmine appears to be dead.
We have found the exact same problem with modern rubies such as 2.3, 2.4, 2.5.
The summary is that due to fork and sharing of established connections in the
DRbConn pool, the
DRb server sometimes sends
DRb client 1's message to client 2 and client 2's message to client 1.
My colleague Adam Grare and I have narrowed it down to the "global"
DRb::DRbConn class instance variable
@pool being inherited in child forked processes.
Our workaround was to close all existing connections in the inherited pool in each fork to ensure each child fork process would get brand new connections:
DRb::DRbConn.instance_variable_get(:@mutex).synchronize do DRb::DRbConn.instance_variable_get(:@pool).each(&:close) end
The attached client and server and log demonstrates the problem and fails on all modern ruby versions. The source of these can be found in a gist here: . Note, we have tested this on Mac OSX and debian.
It would be great if connection pools would not be shared in forked processes or give us a public interface to clear the connection pool.