Skip to content

Commit

Permalink
don't kill if pid same as file (#8997) (#8998)
Browse files Browse the repository at this point in the history
* don't kill if pid same as file (#8997)

* test for don't kill if pid same as file (#8997)

* restore file permission

---------

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
  • Loading branch information
lewijw and auvipy committed May 5, 2024
1 parent 91c5b90 commit 77dbc05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions celery/platforms.py
Expand Up @@ -186,6 +186,9 @@ def remove_if_stale(self):
if not pid:
self.remove()
return True
if pid == os.getpid():
# this can be common in k8s pod with PID of 1 - don't kill
return True

try:
os.kill(pid, 0)
Expand Down
9 changes: 9 additions & 0 deletions t/unit/utils/test_platforms.py
Expand Up @@ -689,6 +689,15 @@ def test_remove_if_stale_no_pidfile(self):
assert p.remove_if_stale()
p.remove.assert_called_with()

def test_remove_if_stale_same_pid(self):
p = Pidfile('/var/pid')
p.read_pid = Mock()
p.read_pid.return_value = os.getpid()
p.remove = Mock()

assert p.remove_if_stale()
p.remove.assert_not_called()

@patch('os.fsync')
@patch('os.getpid')
@patch('os.open')
Expand Down

1 comment on commit 77dbc05

@auvipy
Copy link
Member

@auvipy auvipy commented on 77dbc05 May 7, 2024

Choose a reason for hiding this comment

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

this need adjustment right way with this PR? #9007

Please sign in to comment.