Skip to content

windows programs compiled with cgo do not set exception handler #3543

@LukeMauldin

Description

@LukeMauldin
What steps will reproduce the problem?
1.  Compile and run the attached code on Windows 7 or Windows Server 2008 R2.
2.  The entire Go process will crash when accessing the URL http://localhost:8181/Test

What is the expected output?
The expected output is that a stack trace will be printed from the panic and that the
goroutine serving the request will fail but that the entire web server process will not
crash.

What do you see instead?
The web server process crashes.

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Tested on Windows 7 X64, Windows Server 2008 R2 and the web server process crashes. 
Tested on Ubuntu X64 and the web server process does not crash and the panic stack trace
is printed correctly.

Which version are you using?  (run 'go version')
go version weekly.2012-03-27 +99292bad0d6d

Please provide any additional information below.
Below is an output from GDB debugging the program on Windows.  As you can see, the first
time the URL was accessed, the program did not crash but correctly printed the stack
trace.  However, the second time the URL was accessed, GDB received 2 seg faults and the
entire program crashed.  The majority of the time the web server process crashes every
time.  
The problem seems to occur less often if I do not import the mgodbc.go file.  Also, I
have been unable to reproduce the problem outside of a web server process.

(gdb) r
Starting program: C:\Users\lmauldin\Documents\Eclipse\TestWebCrash\bin\main.exe

[New Thread 4436.0x25f0]
[New Thread 4436.0x1380]
[New Thread 4436.0x1e24]
[New Thread 4436.0xea0]
[New Thread 4436.0x1c30]

Program received signal SIGSEGV, Segmentation fault.
main.WebTest ()
    at C:/Users/lmauldin/Documents/Eclipse/TestWebCrash/src/main.go:22
22              _ = *s
(gdb) c
Continuing.
[New Thread 4436.0x1844]
2012/04/17 18:24:48 http: panic serving 127.0.0.1:52340: runtime error: invalid
memory address or nil pointer dereference
c:/GoBuild/go/src/pkg/net/http/server.go:576 (0x43f446)
        _func_003: buf.Write(debug.Stack())
c:/GoBuild/go/src/pkg/runtime/proc.c:1443 (0x411086)
        panic: reflect-+call(d->fn, d->args, d->siz);
c:/GoBuild/go/src/pkg/runtime/runtime.c:129 (0x411bee)
        panicstring: runtime-+panic(err);
c:/GoBuild/go/src/pkg/runtime/thread_windows.c:276 (0x414bd5)
        sigpanic: runtime-+panicstring("invalid memory address or nil pointer de
reference");
C:/Users/lmauldin/Documents/Eclipse/TestWebCrash/src/main.go:22 (0x401144)
        WebTest: _ = *s
c:/GoBuild/go/src/pkg/net/http/server.go:690 (0x4333da)
        HandlerFunc.ServeHTTP: f(w, r)
c:/GoBuild/go/src/pkg/net/http/server.go:926 (0x43427d)
        (*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
c:/GoBuild/go/src/pkg/net/http/server.go:656 (0x4331e7)
        (*conn).serve: handler.ServeHTTP(w, w.req)
c:/GoBuild/go/src/pkg/runtime/proc.c:271 (0x40efc2)
        goexit: runtime-+goexit(void)

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 4436.0x1c30]
main.WebTest ()
    at C:/Users/lmauldin/Documents/Eclipse/TestWebCrash/src/main.go:22
22              _ = *s
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
main.WebTest ()
    at C:/Users/lmauldin/Documents/Eclipse/TestWebCrash/src/main.go:22
22              _ = *s
(gdb) c
Continuing.
[Inferior 1 (process 4436) exited with code 030000000005]
(gdb) bt
No stack.
(gdb)

Attachments:

  1. main.go (356 bytes)
  2. config.go (77 bytes)
  3. mgodbc.go (24860 bytes)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions