How do I debug memory related errors? panic serving [::1]:59182: runtime error: invalid memory address or nil pointer dereference

1,133 views
Skip to first unread message

deepak

unread,
Aug 26, 2013, 8:54:42 AM8/26/13
to golan...@googlegroups.com
Hi all, 

I am new to go programming, I just wrote a http server program based on the tutorial here. The code is working fine in linux ( I am using linux mint 14 with go version 1.0.2). But when I demoed it to my friend in a mac machine with go version 1.1.2 it crashed while serving the request. My question is how do I debug these sort of errors, what tools can be used? Any articles on inspecting these sort of errors would be helpful. Also right now I have no idea how to fix this.


when running the code I am getting this error ( go version 1.1.2 mac os x 10.7.5)

2013/08/26 18:09:36 GET HTTP/1.1 /
2013/08/26 18:09:36 http: panic serving [::1]:59182: runtime error: invalid memory address or nil pointer dereference
goroutine 4 [running]:
net/http.func·007()
/usr/local/go/src/pkg/net/http/server.go:1022 +0x9c
main.handleRoute(0x18a368, 0x5, 0x11469de0, 0x11478400, 0x11475310, ...)
/Users/deepak/Work/Go/programs/server/server.go:61 +0x1c1
main.router(0x11469de0, 0x11478400, 0x11453850)
/Users/deepak/Work/Go/programs/server/server.go:69 +0x11a
net/http.HandlerFunc.ServeHTTP(0x1c80cc, 0x11469de0, 0x11478400, 0x11453850)
/usr/local/go/src/pkg/net/http/server.go:1149 +0x39
net/http.(*ServeMux).ServeHTTP(0x11469660, 0x11469de0, 0x11478400, 0x11453850)
/usr/local/go/src/pkg/net/http/server.go:1416 +0xda
net/http.serverHandler.ServeHTTP(0x1146d270, 0x11469de0, 0x11478400, 0x11453850)
/usr/local/go/src/pkg/net/http/server.go:1517 +0x11e
net/http.(*conn).serve(0x114722d0)
/usr/local/go/src/pkg/net/http/server.go:1096 +0x650
created by net/http.(*Server).Serve
/usr/local/go/src/pkg/net/http/server.go:1564 +0x23f
^[[A^[[A^Cexit status 2


Thanks

Deepak

Kyle Lemons

unread,
Aug 26, 2013, 4:00:00 PM8/26/13
to deepak, golang-nuts
Upgrade to go 1.1.1, add debug prints for the values used in that line, and try the race tool.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Kyle Lemons

unread,
Aug 26, 2013, 4:00:26 PM8/26/13
to deepak, golang-nuts
whoops, 1.1.2*

Dave Cheney

unread,
Aug 26, 2013, 5:37:43 PM8/26/13
to deepak, golan...@googlegroups.com
Please ensure you handle all errors. Your program is crashing on line 61 because your program assumes that load("404") always succeeds. It is failing because you are making assumptions about the working directory your program is running from. 


--

deepak kumar

unread,
Aug 29, 2013, 2:38:57 AM8/29/13
to Dave Cheney, golan...@googlegroups.com
sorry for the delay in response, I was out of station.

@Kyle could you be more specific about the race tool. 

In this code the error message didn't gave me any insight about the wrong directory path, it was saying something related to network, so I was kind of confused.

Thanks Dave, I didn't notice the path while showing it to my friend I just forgot to use /Users in mac as users directory.
--
Thanks & Regards
Deepak Kumar
+91-9895821948 | skype: deepakkumarnd | twitter: @_deepak0


Reply all
Reply to author
Forward
0 new messages