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

Conversation

agrare
Copy link
Member

@agrare agrare commented Feb 5, 2018

DRb::DRbConn keeps a global pool of open connections which is shared by
child processes when they are forked from a parent. If this parent
executes a DRb call prior to forking a child process the child picks up
this open connection and uses it which can cause replies from the server
to go to the wrong DRb client.

The connection pool in question is here

There is a long standing ruby bug https://bugs.ruby-lang.org/issues/2718
which describes the issue and has reproducer code attached.

This is the reproducer code that we used: https://gist.github.com/agrare/d9484884bd297b1615814128129cfc5c

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1385038

@agrare
Copy link
Member Author

agrare commented Feb 5, 2018

/cc @jrafanie @Fryguy @blomquisg

@agrare
Copy link
Member Author

agrare commented Feb 5, 2018

Output from a run without clearing the connection pool. This shows all of the commonly hit issues, incompatible marshal file, too large packet, and just the wrong message returned:

ruby drb_test_script.rb
....incompatible marshal file format (can't be read)
	format version 4.8 required; 0.0 given
too large packet 67654656
too large packet 67651874
too large packet 1090927110
too large packet 155271489
.Failure! expected BBBB but got AAAA
too large packet 140928614430267 too large packet 1163133960
incompatible marshal file format (can't be read)
	format version 4.8 required; 14.4 given

too large packet 1094795526
too large packet 97348949230276 too large packet 1226967361

incompatible marshal file format (can't be read)
	format version 4.8 required; 0.0 giventoo large packet 67651874

too large packet 6765465630248 too large packet 155271489

# 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/drb'
Copy link
Member

Choose a reason for hiding this comment

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

#MAJOR HACK approaching...

It's a stable api since it's been there since at least 2003 😆 🤣

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

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

This is as clean as it's going to get. 👍

@jrafanie
Copy link
Member

jrafanie commented Feb 6, 2018

to go to the wrong process.

Maybe say " to go to the wrong drb client"`

@agrare
Copy link
Member Author

agrare commented Feb 6, 2018

Maybe say " to go to the wrong drb client"`

Great point, also @Fryguy mentioned we might want to synchronize on that mutex so I'll make both of those changes

DRb::DRbConn keeps a global pool of open connections which is shared by
child processes when they are forked from a parent.  If this parent
executes a DRb call prior to forking a child process the child picks up
this open connection and uses it which can cause replies from the server
to go to the wrong DRb client.

There is a long standing ruby bug https://bugs.ruby-lang.org/issues/2718
which describes the issue and has reproducer code attached.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1385038
@agrare agrare force-pushed the bz_1385038_fix_shared_drb_connections_after_fork branch from ea7e425 to 271ae40 Compare February 6, 2018 16:07
@agrare
Copy link
Member Author

agrare commented Feb 6, 2018

Okay updated the commit message per #16953 (comment) and synchronize on the DRbConn.mutex while closing pool connections per @Fryguy

@juliancheal
Copy link
Member

@agrare can we have a method called deadpool :)

@miq-bot
Copy link
Member

miq-bot commented Feb 6, 2018

Checked commit agrare@271ae40 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. ⭐

@jrafanie
Copy link
Member

jrafanie commented Feb 6, 2018

@agrare can you add the branches to backport this to?

@jrafanie jrafanie merged commit b6062af into ManageIQ:master Feb 6, 2018
@jrafanie jrafanie self-assigned this Feb 6, 2018
@jrafanie jrafanie added this to the Sprint 79 Ending Feb 12, 2018 milestone Feb 6, 2018
@agrare agrare deleted the bz_1385038_fix_shared_drb_connections_after_fork branch February 6, 2018 18:19
@agrare
Copy link
Member Author

agrare commented Feb 6, 2018

@jrafanie done, between the original BZ and the 3 clones this PR has a combined PM score of 30,820 😆

simaishi pushed a commit that referenced this pull request Feb 6, 2018
…ctions_after_fork

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

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1542735
@simaishi
Copy link
Contributor

simaishi commented Feb 6, 2018

Gaprindashvili backport details:

$ git log -1
commit dfebca64b99c5cdebd8f0c9ef5f0b90f05575a4c
Author: Joe Rafaniello <jrafanie@users.noreply.github.com>
Date:   Tue Feb 6 13:19:25 2018 -0500

    Merge pull request #16953 from agrare/bz_1385038_fix_shared_drb_connections_after_fork
    
    Close open connections from parent after fork
    (cherry picked from commit b6062afc980377b30755f6ffdf0e91d64ccdbf11)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1542735

simaishi pushed a commit that referenced this pull request Feb 6, 2018
…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
@simaishi
Copy link
Contributor

simaishi commented Feb 6, 2018

Fine backport details:

 $ git log -1
commit 3553fe85ebcb1a43351a92026dacd92ca90a570c
Author: Joe Rafaniello <jrafanie@users.noreply.github.com>
Date:   Tue Feb 6 13:19:25 2018 -0500

    Merge pull request #16953 from agrare/bz_1385038_fix_shared_drb_connections_after_fork
    
    Close open connections from parent after fork
    (cherry picked from commit b6062afc980377b30755f6ffdf0e91d64ccdbf11)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1481378

@jrafanie
Copy link
Member

I opened https://bugs.ruby-lang.org/issues/14471 to reopen the existing ruby bug

simaishi pushed a commit that referenced this pull request Feb 26, 2018
…ctions_after_fork

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

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1481677
@simaishi
Copy link
Contributor

Euwe backport details:

$ git log -1
commit 8a1af174c8478711b581da373a316aebb4e3b7d0
Author: Joe Rafaniello <jrafanie@users.noreply.github.com>
Date:   Tue Feb 6 13:19:25 2018 -0500

    Merge pull request #16953 from agrare/bz_1385038_fix_shared_drb_connections_after_fork
    
    Close open connections from parent after fork
    (cherry picked from commit b6062afc980377b30755f6ffdf0e91d64ccdbf11)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1481677

d-m-u pushed a commit to d-m-u/manageiq that referenced this pull request Jun 6, 2018
…rb_connections_after_fork

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

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1481378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants