diff --git a/celery/platforms.py b/celery/platforms.py index 6203f2c29b5..1375fd82c0b 100644 --- a/celery/platforms.py +++ b/celery/platforms.py @@ -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) diff --git a/t/unit/utils/test_platforms.py b/t/unit/utils/test_platforms.py index ab1a9436543..3f4e47ae339 100644 --- a/t/unit/utils/test_platforms.py +++ b/t/unit/utils/test_platforms.py @@ -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')