Skip to content

Windows programs throw uncaught Invalid HANDLE exception on exit

If I compile the following program

module Main where

main = return ()

on Windows XP with the command line

ghc --make Main.hs

and then run the program inside Microsoft Visual Studio 2003 (by right clicking main.exe and selecting Debug -> MS VS 2003 from the context menu) I get the following output in the Visual Studio output pane (full path to main.exe elided for clarity):

'main.exe': Loaded 'C:\...\main.exe', No symbols loaded.
'main.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'main.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'main.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'main.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'main.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'main.exe': Loaded 'C:\WINDOWS\system32\wsock32.dll', No symbols loaded.
'main.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll', No symbols loaded.
'main.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll', No symbols loaded.
'main.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'main.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
The thread 'Win32 Thread' (0x630) has exited with code 0 (0x0).
First-chance exception at 0x7c90eb74 in main.exe: 0xC0000008: An invalid HANDLE was specified.
Unhandled exception at 0x7c90eb74 in main.exe: 0xC0000008: An invalid HANDLE was specified.
The program '[1540] main.exe: Native' has exited with code 0 (0x0).

If the program is run outside Visual Studio no problems are visible (ie the program exits silently as expected) but presumably the same behaviour is happening internally. My first guess is that perhaps the RTS exit code is trying to use a handle to the thread that has already exited, but this is only a wild guess.

Trac metadata
Trac field Value
Version 6.6
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Runtime System
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information