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:


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:

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:


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 ...

$ ./ ./Foo
start main

$ 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

$ ./ ./c  
start main

$ ./ ./c
start main
end main

$ ./ ./c
start main

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:

$ ./ 
+ 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

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

$ time ./q.exe 5 ./Foo
start main
end main

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.