Opened 12 years ago

Closed 12 years ago

#1599 closed bug (fixed)

testsuite timeout doesn't kill subprocesses on Windows

Reported by: simonmar Owned by: igloo
Priority: normal Milestone: 6.8 branch
Component: Test Suite Version: 6.6.1
Keywords: Cc:
Operating System: Windows Architecture: x86
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The timeout program doesn't kill subprocesses on Windows, which means for example that if GHCi hangs, timeout only kills ghc-inplace and not the GHC binary itself. The hung GHC process prevents the build tree from being removed, and stops future buildbots from running.

I just came across this Python code which allegedly does both timeout and subprocess-killing on Windows:

http://benjamin.smedbergs.us/blog/2006-12-11/killableprocesspy/

This could be either used directly (it's Mozilla-licensed) or we could adapt the idea for our timeout program.

Attachments (1)

q.hsc (6.9 KB) - added by igloo 12 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 12 years ago by igloo

Owner: set to igloo

comment:2 Changed 12 years ago by igloo

Using this python program:

#!/usr/bin/python

from killableprocess import *
from sys import argv

p = Popen(args=argv[1])
r = p.wait(timeout=1)
print r

and this Haskell program:

import Foreign.C
import System.Cmd
import System.IO

main :: IO ()
main = do hSetBuffering stdout NoBuffering
          putStrLn "start main"
          -- rawSystem "c:/cygwin/bin/sh"
          --           ["-c", "echo wibble; sleep 3; echo flibble"]
          -- system "sh -c \"echo wibble; sleep 3; echo flibble\""
          withCString "sh -c \"echo wibble; sleep 3; echo flibble\"" s
          putStrLn "end main"

foreign import ccall "stdlib.h system" s :: CString -> IO CInt

it doesn't seem to work (the "flibble" on the last line is printed after the command has terminated):

$ ghc --make Foo -fffi
[1 of 1] Compiling Main             ( Foo.hs, Foo.o )
Linking Foo.exe ...

$ ./ptimeout.py ./Foo
start main
wibble
-9

$ flibble

Even with this C program:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
      printf("start main\n");
      system("sh -c \"echo wibble; sleep 3; echo flibble\"");
      printf("end main\n");
}

it doesn't seem to work right:

$ gcc c.c -o c

$ ./ptimeout.py ./c  
start main
wibble
flibble
-9

$ ./ptimeout.py ./c
start main
wibble
-9
end main

$ ./ptimeout.py ./c
start main
wibble
-9

The C++ program that is linked to also doesn't work for me:

$ Debug/killableprocess.exe ./c
start main
end main

$

I'll try to investigate further.

Changed 12 years ago by igloo

Attachment: q.hsc added

comment:3 Changed 12 years ago by igloo

OK, q.hsc does the business:

$ ./build.sh 
+ hsc2hs q.hsc
+ ghc --make q.hs
[1 of 1] Compiling Main             ( q.hs, q.o )
Linking q.exe ...

$ time ./q.exe 1 ./Foo
start main
wibble

real    0m1.331s
user    0m0.010s
sys     0m0.000s

$ time ./q.exe 5 ./Foo
start main
wibble
flibble
end main
('A',0)

real    0m3.175s
user    0m0.020s
sys     0m0.010s

Now it just needs splitting into 2 and merging into the Win32 package and testsuite timeout program.

comment:4 Changed 12 years ago by igloo

Resolution: fixed
Status: newclosed

The timeout program in the testsuite now does this.

Note: See TracTickets for help on using tickets.