Opened 13 years ago

Closed 13 years ago

#942 closed bug (fixed)

Windows programs throw uncaught Invalid HANDLE exception on exit

Reported by: brianh@… Owned by: igloo
Priority: normal Milestone: 6.6.1
Component: Runtime System Version: 6.6
Keywords: uncaught exception HANDLE exit Cc:
Operating System: Windows Architecture: x86
Type of failure: None/Unknown Test Case: N/A
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

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.

Change History (6)

comment:1 Changed 13 years ago by igloo

Milestone: 6.6.1
Test Case: N/A

Can anyone tell me how to reproduce this with VS 2005 please (I don't have the Debug menu mentioned)?

comment:2 Changed 13 years ago by brianh@…

If there is no Debug context menu in Windows Explorer when you navigate to main.exe, another way to get VS 2003 to debug the program is by creating a new C++ project in VS 2003, removing the source and header files from the project (and the project directory), then create a Debug sub directory in the project folder and copy main.exe into it. You need to rename main.exe to have the same name as the project. Then hit F5 in VS 2003 and VS will debug the program. I assume this technique should also work in VS 2005 but unfortunately I only have VS 2003 on my computer.

comment:3 Changed 13 years ago by brianh@…

severity: normalmajor

I've changed the severity to major because I feel this bug prevents me distributing any binaries compiled under ghc6.6 for Windows, since whether or not the bug is "visible" (ie if you choose to run the binary under a debugger), obviously something is very wrong indeed with the runtime or else it wouldn't be trying to use an invalid handle (or cause one of the windows DLLs to do so) at program exit.

comment:4 Changed 13 years ago by igloo

Owner: set to igloo

comment:5 Changed 13 years ago by igloo

This seems to be fixed in the HEAD. The 6.6 branch isn't building for me on Windows at the moment, so I haven't checked it yet.

comment:6 Changed 13 years ago by igloo

Resolution: fixed
Status: newclosed

I've now confirmed that it also works in the 6.6 branch.

Note: See TracTickets for help on using tickets.