Skip to content

Commit

Permalink
Try sending SIGTERM before SIGKILL
Browse files Browse the repository at this point in the history
  • Loading branch information
jlg authored and Dustin J. Mitchell committed Sep 22, 2010
1 parent 915adfd commit 5cbbe99
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions slave/buildslave/runprocess.py
Expand Up @@ -160,6 +160,9 @@ class RunProcess:
"""

notreally = False
TERM = "TERM"
TERM_TIMEOUT = 20

BACKUP_TIMEOUT = 5
KILL = "KILL"
CHUNK_LIMIT = 128*1024
Expand Down Expand Up @@ -652,12 +655,17 @@ def doMaxTimeout(self):
msg = "command timed out: %d seconds elapsed" % self.maxTime
self.kill(msg)

def kill(self, msg):
def kill(self, msg, signame=None):
if signame is None:
signame = self.TERM
# This may be called by the timeout, or when the user has decided to
# abort this build.
self._sendBuffers()
if self.timer:
self.timer.cancel()
try: # this can be already called when TERM was unsuccesfull
self.timer.cancel()
except:
pass
self.timer = None
if self.maxTimer:
self.maxTimer.cancel()
Expand All @@ -684,12 +692,12 @@ def kill(self, msg):

sig = None
if self.KILL is not None:
sig = getattr(signal, "SIG"+ self.KILL, None)
sig = getattr(signal, "SIG"+ signame, None)

if self.KILL == None:
log.msg("self.KILL==None, only pretending to kill child")
elif sig is None:
log.msg("signal module is missing SIG%s" % self.KILL)
log.msg("signal module is missing SIG%s" % signame)
elif not hasattr(os, "kill"):
log.msg("os module is missing the 'kill' function")
elif not hasattr(self.process, "pid") or self.process.pid is None:
Expand All @@ -709,9 +717,9 @@ def kill(self, msg):
if self.KILL is None:
log.msg("self.KILL==None, only pretending to kill child")
else:
log.msg("trying process.signalProcess('KILL')")
self.process.signalProcess(self.KILL)
log.msg(" signal %s sent successfully" % (self.KILL,))
log.msg("trying process.signalProcess('%s')" % (signame, ))
self.process.signalProcess(signame)
log.msg(" signal %s sent successfully" % (signame,))
hit = 1
except OSError:
# could be no-such-process, because they finished very recently
Expand All @@ -725,10 +733,16 @@ def kill(self, msg):
# stderr. This is weird.
self.pp.transport.loseConnection()

# finished ought to be called momentarily. Just in case it doesn't,
# set a timer which will abandon the command.
self.timer = self._reactor.callLater(self.BACKUP_TIMEOUT,
self.doBackupTimeout)
# we tried TERM first, next it's time for KILL
if self.KILL is not None and signame != self.KILL:
self.timer = self._reactor.callLater(self.TERM_TIMEOUT,
self.kill, msg=msg, signame=self.KILL)

else:
# finished ought to be called momentarily. Just in case it doesn't,
# set a timer which will abandon the command.
self.timer = self._reactor.callLater(self.BACKUP_TIMEOUT,
self.doBackupTimeout)

def doBackupTimeout(self):
log.msg("we tried to kill the process, and it wouldn't die.."
Expand Down

0 comments on commit 5cbbe99

Please sign in to comment.