[SERVER-37125] Powercycle should ignore a process reference if it no longer exists Created: 13/Sep/18  Updated: 29/Oct/23  Resolved: 30/Apr/21

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: None
Fix Version/s: 4.9.0-rc1, 4.0.25, 4.2.15, 4.4.7, 5.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Jonathan Abrahams Assignee: Mikhail Shchatko
Resolution: Fixed Votes: 0
Labels: tig-bfday-eligible, tig-powercycle
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Duplicate
is duplicated by SERVER-37493 Powercycle kill_mongod should not fai... Closed
Related
is related to SERVER-36431 Powercycle should check for existence... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.9, v4.4, v4.2, v4.0, v3.6
Sprint: STM 2021-05-17
Participants:
Linked BF Score: 46
Story Points: 1

 Description   

All references in powercycle.py to psutil.Process(pid) should be done in a try/except block.



 Comments   
Comment by Githook User [ 12/May/21 ]

Author:

{'name': 'Mikhail Shchatko', 'email': 'mikhail.shchatko@mongodb.com', 'username': 'MikhailShchatko'}

Message: SERVER-37125 Remove unused ProcessControl code
Branch: v4.4
https://github.com/mongodb/mongo/commit/8c0f28f029863fc38076e57c0b9d4244bc2f8c41

Comment by Githook User [ 30/Apr/21 ]

Author:

{'name': 'Mikhail Shchatko', 'email': 'mikhail.shchatko@mongodb.com', 'username': 'MikhailShchatko'}

Message: SERVER-37125 Remove unused ProcessControl code
Branch: master
https://github.com/mongodb/mongo/commit/63724eaa357ef80f3b79566f30e8a6c1e2c07ed4

Comment by Githook User [ 30/Apr/21 ]

Author:

{'name': 'Mikhail Shchatko', 'email': 'mikhail.shchatko@mongodb.com', 'username': 'MikhailShchatko'}

Message: SERVER-37125 Remove unused ProcessControl code

(cherry picked from commit b9d9a010494018dce57a95793cb81a4a317119aa)
Branch: v4.2
https://github.com/mongodb/mongo/commit/508ae0386a99d41f107491d352322c05158bbdf8

Comment by Githook User [ 30/Apr/21 ]

Author:

{'name': 'Mikhail Shchatko', 'email': 'mikhail.shchatko@mongodb.com', 'username': 'MikhailShchatko'}

Message: SERVER-37125 Remove unused ProcessControl code

(cherry picked from commit 08459b3b33a4c5567bcea75d3d33e2937a467252)
Branch: v4.9
https://github.com/mongodb/mongo/commit/17d7453f95b4c1dfa439adb4532a82015c9a7d81

Comment by Githook User [ 30/Apr/21 ]

Author:

{'name': 'Mikhail Shchatko', 'email': 'mikhail.shchatko@mongodb.com', 'username': 'MikhailShchatko'}

Message: SERVER-37125 Powercycle should ignore a process reference if it no longer exists
Branch: v4.0
https://github.com/mongodb/mongo/commit/57325793ec1de736a667a0f27904fb5d2d4c059e

Comment by Jonathan Abrahams [ 01/Nov/18 ]

We should surround all references to a process in class ProcessControl with a try/except:

    def get_pids(self):
        """ Return list of process ids for process 'self.name'."""
        if not self.name:
            return self.pids
        self.pids = []
        for proc in psutil.process_iter():
            if proc.name() == self.name:
                try:
                    self.pids.append(proc.pid)
                except psutil.NoSuchProcess:
                    pass
        return self.pids
 
    def get_name(self):
        """ Return process name or name of first running process from pids."""
        if not self.name:
            for pid in self.get_pids():
                proc = psutil.Process(pid)
                if psutil.pid_exists(pid):
                    try:
                        self.name = proc.name()
                        break
                    except psutil.NoSuchProcess:
                        pass
        return self.name
 
    def get_procs(self):
        """ Return a list of 'proc' for the associated pids."""
        procs = []
        for pid in self.get_pids():
            try:
                procs.append(psutil.Process(pid))           
            except psutil.NoSuchProcess:
                pass
         return procs
 
    def kill(self):
        """ Kill all running processes that match the list of pids. """
        if self.is_running():
            for proc in self.get_procs():
                try:
                    proc.kill()
                except psutil.NoSuchProcess:
                    LOGGER.info("Could not kill process with pid %d, as it no longer exists",
                                proc.pid)

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