[SERVER-36431] Powercycle should check for existence of a process before accessing it's attributes Created: 03/Aug/18  Updated: 29/Oct/23  Resolved: 13/Aug/18

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: None
Fix Version/s: 4.1.2

Type: Bug Priority: Major - P3
Reporter: Jonathan Abrahams Assignee: Jonathan Abrahams
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Related
related to SERVER-37125 Powercycle should ignore a process re... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0, v3.6
Sprint: TIG 2018-08-27
Participants:
Linked BF Score: 46
Story Points: 1

 Description   

It's possible then when iterating over a list of processes that the process could finish before it's accessed:

        for proc in psutil.process_iter():
            if proc.name() == self.name:
                self.pids.append(proc.pid)

An additional check should be added

if psutil.pid_exists(proc.pid) and proc.name() == self.name



 Comments   
Comment by Githook User [ 13/Aug/18 ]

Author:

{'name': 'Jonathan Abrahams', 'email': 'jonathan@mongodb.com', 'username': 'hptabster'}

Message: SERVER-36431 Powercycle should check for existence of a process before accessing it's attributes
Branch: master
https://github.com/mongodb/mongo/commit/f46d77c794e0da816ab4c93b0cb6ace2b771a428

Comment by Max Hirschhorn [ 04/Aug/18 ]

Calling psutil.pid_exists() and then calling psutil.Process.name() "very quickly" is still a race. We should instead just continue if proc.name() raises a psutil.NoSuchProcess exception as we only care about getting the list of live processes matching self.name.

Generated at Thu Feb 08 04:43:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.