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

Only remove my process' pidfile. #15491

Merged

Conversation

jrafanie
Copy link
Member

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

at_exit handlers created in the server process are inherited when the
server forks workers. As soon as one of these workers exits, this
at_exit was being run and removing the server's pidfile. This allowed a
subsequent rake evm:start or systemctl start evmserverd to fail to
detect an existing server process, allowing a second MIQ Server to
start.

We can workaround this by only removing a pidfile that matches my
Process.pid.

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

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

Nice, simple change 👍 I tested on an appliance and verified it fixed the bug.

lib/pid_file.rb Outdated
@@ -27,7 +27,7 @@ def remove
def create(remove_on_exit = true)
FileUtils.mkdir_p(File.dirname(@fname))
File.open(@fname, "w") { |f| f.write(Process.pid) }
at_exit { PidFile.remove(@fname) } if remove_on_exit
at_exit { PidFile.remove(@fname) if PidFile.new(@fname).pid == Process.pid } if remove_on_exit
Copy link
Member

@Fryguy Fryguy Jun 30, 2017

Choose a reason for hiding this comment

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

Can this logic be pushed down into PidFile? Perhaps PidFile.remove! or PidFile.safe_remove?

Copy link
Member

Choose a reason for hiding this comment

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

Gah...I didn't realize this was PidFile class 😖

Even so, what do you think of a different method to separate the concerns?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're in pidfile, let me try pushing it down to remove

@jrafanie jrafanie force-pushed the do_not_remove_other_process_pidfile branch from 9d39865 to 800c6e0 Compare June 30, 2017 21:25
@@ -21,7 +21,7 @@ def pid
end

def remove
FileUtils.rm(@fname) if File.file?(@fname)
FileUtils.rm(@fname) if pid == Process.pid
Copy link
Member Author

Choose a reason for hiding this comment

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

The pid method checks if the File exists... good idea @Fryguy

@gtanzillo gtanzillo self-assigned this Jun 30, 2017
@jrafanie jrafanie force-pushed the do_not_remove_other_process_pidfile branch from 800c6e0 to 2134728 Compare June 30, 2017 21:53
https://bugzilla.redhat.com/show_bug.cgi?id=1464698

at_exit handlers created in the server process are inherited when the
server forks workers.  As soon as one of these workers exits, this
at_exit was being run and removing the server's pidfile.  This allowed a
subsequent rake evm:start or systemctl start evmserverd to fail to
detect an existing server process, allowing a second MIQ Server to
start.

We can workaround this by only removing a pidfile that matches my
Process.pid.
@jrafanie jrafanie force-pushed the do_not_remove_other_process_pidfile branch from 2134728 to 9090b3e Compare June 30, 2017 21:54
@miq-bot
Copy link
Member

miq-bot commented Jun 30, 2017

Checked commit jrafanie@9090b3e with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 👍

@gtanzillo gtanzillo added this to the Sprint 64 Ending Jul 3, 2017 milestone Jul 1, 2017
@gtanzillo gtanzillo merged commit 8dff3ce into ManageIQ:master Jul 1, 2017
@jrafanie jrafanie deleted the do_not_remove_other_process_pidfile branch July 6, 2017 15:10
simaishi pushed a commit that referenced this pull request Jul 7, 2017
@simaishi
Copy link
Contributor

simaishi commented Jul 7, 2017

Euwe backport details:

$ git log -1
commit 9e7ca6741f542eeef9cbd05f02dfae0487074ac3
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Sat Jul 1 07:03:04 2017 -0400

    Merge pull request #15491 from jrafanie/do_not_remove_other_process_pidfile
    
    Only remove my process' pidfile.
    (cherry picked from commit 8dff3ce84db537aad522c580ce786c002a57548d)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1468612

simaishi pushed a commit that referenced this pull request Aug 4, 2017
@simaishi
Copy link
Contributor

simaishi commented Aug 4, 2017

Fine backport details:

$ git log -1
commit cdd920a7ab17b7c9d20065a26103a4649f9da823
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Sat Jul 1 07:03:04 2017 -0400

    Merge pull request #15491 from jrafanie/do_not_remove_other_process_pidfile
    
    Only remove my process' pidfile.
    (cherry picked from commit 8dff3ce84db537aad522c580ce786c002a57548d)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1478434

simaishi pushed a commit that referenced this pull request Aug 23, 2017
@simaishi
Copy link
Contributor

Darga backport details:

$ git log -1
commit 25d71d8ffe7b96e17d63d918bc7352c3c1e10eab
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Sat Jul 1 07:03:04 2017 -0400

    Merge pull request #15491 from jrafanie/do_not_remove_other_process_pidfile
    
    Only remove my process' pidfile.
    (cherry picked from commit 8dff3ce84db537aad522c580ce786c002a57548d)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1484485

d-m-u pushed a commit to d-m-u/manageiq that referenced this pull request Jun 6, 2018
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