Opened 12 years ago

Last modified 7 years ago

#387 new defect

TerminateProcess fails in

Reported by: griels Owned by:
Priority: major Milestone: 0.9.+
Version: 0.7.5 Keywords: windows

Description sometimes fails to kill the Buildbot process:

Event Type: Warning Event Source: BuildBot Event Category: None Event ID: 255 Date: 23/11/2008 Time: 23:00:44 User: N/A Computer: DOGBOLTER Description: BuildBot process at u'c:\ProsodyTest?\BuildBot\build-master' failed to terminate - killing it

Event Type: Error Event Source: BuildBot Event Category: None Event ID: 3 Date: 23/11/2008 Time: 23:00:49 User: N/A Computer: DOGBOLTER Description: The instance's SvcRun?() method failed

File "", line 785, in SvcRun?


File "", line 274, in SvcDoRun?

win32api.TerminateProcess?(h, 3)

pywintypes.error: (5, 'TerminateProcess?', 'Access is denied.')

Using Python 2.4 on a Windows XP build-master.

Attachments (1) (2.5 KB) - added by LRN 8 years ago.
Sample code for safe process termination

Download all attachments as: .zip

Change History (9)

comment:1 Changed 12 years ago by griels

  • Summary changed from TerminateProcess fails to TerminateProcess fails in
  • Version changed from 0.7.9 to 0.7.5

comment:2 Changed 12 years ago by griels

The script is launched from a Scheduled Task run with local Administrator privileges. Buildbot is restarted on a daily basis by this script and it usually works - perhaps this is because Buildbot normally shuts down cleanly within the 3000ms timeout, so the TerminateProcess? command is not required.

I checked into TerminateProcess? bugs/issues and didn't find much other than this:

Which suggests maybe there are some security issues with brute-force-killing processes, so maybe this is more of a Windows/win32api problem than an issue with the buildbot_service script?

comment:3 Changed 12 years ago by dustin

  • Keywords windows added; terminateprocess terminate process buildbot_service service access denied removed
  • Milestone changed from undecided to 0.7.+

comment:4 Changed 9 years ago by LRN

Last edited 9 years ago by LRN (previous) (diff)

comment:5 Changed 9 years ago by dustin

So from what I can see, there's a timing-related permissions problem with TerminateProcess. The second post gives a safe workaround on Windows, and it doesn't even involve ctypes.

Ideally, this would be implemented in Twisted, but if the Buildbot Windows folks are happy with doing it in Buildbot, I am too.

comment:6 Changed 9 years ago by LRN

There's a timing-related permissions problem (actually, it's not a permissions problem, AFAICS, the process is just in a state in which you can't kill it, no matter how privileged you are) described later in the thread. Safe process terminator can't avoid THAT particular problem.

It could be that TerminateProcess?() has the _same_ problem. If so, this can be diagnosed by catching pywintypes.error of type 5 ("Access denied"), sleeping for N milliseconds, then checking if the process is still alive. If this is the same problem, then process would be dead after N milliseconds, in spite of TerminateProcess?() failing initially with "Access denied".

I haven't actually tried that for TerminateProcess?(), since i've jumped at SafeTerminateProcess?() straight away, trying to fix my TerminateProcess?() problem.

Changed 8 years ago by LRN

Sample code for safe process termination

comment:7 Changed 8 years ago by LRN

Here's some code . You can use it as application (pass pid as its first argument). The code itself can be copied into, and you can call safe_termiate_process_by_pid () on W32 instead of running taskkill.

This code (unlike the one i posted at is actually tested with a buildslave.

comment:8 Changed 7 years ago by dustin

  • Milestone changed from 0.8.+ to 0.9.+

Ticket retargeted after milestone closed

Note: See TracTickets for help on using tickets.