Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic handling and stack trace don't work when GOPATH includes /go/ in it #1287

Open
ralfthewise opened this issue Dec 29, 2017 · 5 comments

Comments

@ralfthewise
Copy link

In a typical setup of go with docker containers (using the official images at https://hub.docker.com/_/golang/) the GOPATH is setup to be /go. The first frame in a panic stack trace is almost always:

/usr/local/go/src/runtime/debug/stack.go:24

The panic handling function findRelevantStackFrame (https://github.com/revel/revel/blob/master/errors.go#L128) has logic to find the first frame in the source path that isn't robust enough and ends up thinking /usr/local/go/src/runtime/debug/stack.go is the first item because it contains /go/src. This results in an actual panic in revel itself, no helpful stacktrace returned to the browser, and output like this:

app server.go:2848: http: panic serving 127.0.0.1:34942: open /go/src/runtime/debug/stack.go: no such file or directory
goroutine 50 [running]:
net/http.(*conn).serve.func1(0xc4203fc000)
	/usr/local/go/src/net/http/server.go:1697 +0xd0
panic(0x895fe0, 0xc42039c060)
	/usr/local/go/src/runtime/panic.go:491 +0x283
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.MustReadLines(0xc42037605a, 0x1e, 0xc42013aad0, 0x1, 0x1)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/util.go:55 +0x83
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.NewErrorFromPanic(0x8b3bc0, 0xc4203fea58, 0x42ab28)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/errors.go:68 +0x4e3
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.handleInvocationPanic(0xc42023c9c0, 0x8b3bc0, 0xc4203fea58)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/panic.go:26 +0x39
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.PanicFilter.func1(0xc42023c9c0)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/panic.go:17 +0x4d
panic(0x8b3bc0, 0xc4203fea58)
	/usr/local/go/src/runtime/panic.go:491 +0x283
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.InterceptorFilter.func1(0xc42023c9c0)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/intercept.go:98 +0x7d
panic(0x8b3bc0, 0xc4203fea58)
	/usr/local/go/src/runtime/panic.go:491 +0x283
github.com/radartools/account-management/backend/app/controllers.Organizations.Index(0xc42023c9c0, 0x20, 0xc420341350)
	/go/src/github.com/radartools/account-management/backend/app/controllers/organizations.go:31 +0x1a6
github.com/radartools/account-management/backend/app/controllers.(*Organizations).Index(0xc42000fa40, 0x0, 0x0)
	<autogenerated>:1 +0x3c
reflect.Value.call(0x913be0, 0xc42000fa40, 0xe13, 0x92665e, 0x4, 0x0, 0x0, 0x0, 0x8725c0, 0x3, ...)
	/usr/local/go/src/reflect/value.go:434 +0x905
reflect.Value.Call(0x913be0, 0xc42000fa40, 0xe13, 0x0, 0x0, 0x0, 0xc42000fa40, 0xe13, 0x10)
	/usr/local/go/src/reflect/value.go:302 +0xa4
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.ActionInvoker(0xc42023c9c0, 0xc4202f6d18, 0x0, 0x1)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/invoker.go:45 +0x5b8
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.CompressFilter(0xc42023c9c0, 0xc4202f6d10, 0x1, 0x2)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/compress.go:84 +0x9c
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.InterceptorFilter(0xc42023c9c0, 0xc4202f6d08, 0x2, 0x3)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/intercept.go:108 +0xee
github.com/radartools/account-management/backend/app.glob..func1(0xc42023c9c0, 0xc4202f6d00, 0x3, 0x4)
	/go/src/github.com/radartools/account-management/backend/app/init.go:54 +0x13f
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.I18nFilter(0xc42023c9c0, 0xc4202f6cf8, 0x4, 0x5)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/i18n.go:212 +0xa1
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.ValidationFilter(0xc42023c9c0, 0xc4202f6cf0, 0x5, 0x6)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/validation.go:269 +0x19b
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.FlashFilter(0xc42023c9c0, 0xc4202f6ce8, 0x6, 0x7)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/flash.go:50 +0x13c
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.SessionFilter(0xc42023c9c0, 0xc4202f6ce0, 0x7, 0x8)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/session.go:158 +0x117
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.ParamsFilter(0xc42023c9c0, 0xc4202f6cd8, 0x8, 0x9)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/params.go:179 +0xb1
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.FilterConfiguringFilter(0xc42023c9c0, 0xc4202f6cd0, 0x9, 0xa)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/filterconfig.go:211 +0x126
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.RouterFilter(0xc42023c9c0, 0xc4202f6cc8, 0xa, 0xb)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/router.go:789 +0x414
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.PanicFilter(0xc42023c9c0, 0xc4202f6cc0, 0xb, 0xc)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/panic.go:20 +0x93
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.glob..func32(0xc42023c9c0, 0xc4202f6cb8, 0xc, 0xd)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/watcher.go:222 +0x7d
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.handleInternal(0xbac0e0, 0xc42024c740)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/server-engine.go:145 +0x3cd
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.(*GoHttpServer).Handle(0xc4202421b0, 0xbaf420, 0xc420416000, 0xc420406000)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/server_adapter_go.go:101 +0x39e
github.com/radartools/account-management/backend/vendor/github.com/revel/revel.(*GoHttpServer).Init.func3(0xbaf420, 0xc420416000, 0xc420406000)
	/go/src/github.com/radartools/account-management/backend/vendor/github.com/revel/revel/server_adapter_go.go:43 +0x48
net/http.HandlerFunc.ServeHTTP(0xc42022f3b0, 0xbaf420, 0xc420416000, 0xc420406000)
	/usr/local/go/src/net/http/server.go:1918 +0x44
net/http.serverHandler.ServeHTTP(0xc42023c1a0, 0xbaf420, 0xc420416000, 0xc420406000)
	/usr/local/go/src/net/http/server.go:2619 +0xb4
net/http.(*conn).serve(0xc4203fc000, 0xbafde0, 0xc420398180)
	/usr/local/go/src/net/http/server.go:1801 +0x71d
created by net/http.(*Server).Serve
	/usr/local/go/src/net/http/server.go:2720 +0x288  section=system

Somewhat related to #1266

@ralfthewise ralfthewise changed the title Panic handling and stack trace don't work in typical docker usage Panic handling and stack trace don't work when GOPATH includes /go/ in it Jan 7, 2018
@notzippy
Copy link
Collaborator

Thanks, will look into this

@djtm
Copy link

djtm commented Jun 18, 2018

Hi,

as a hotfix I've tried:

  • using /golang as gopath with a symlink (ENV GOPATH=/golang)
  • using /lang as gopath with a symlink (ENV GOPATH=/lang)
  • adding the path so that /go/src/runtime/debug/stack.go is actually present.

To my surprise, both didn't help. Any further ideas at least for a hotfix?

@ralfthewise
Copy link
Author

@djtm we were able to work around it with Dockerfiles starting off as such:

FROM golang:1.9.2                                                                                                                                                                                              
MAINTAINER radar <radar@radartools.net>
     
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/gopath/bin
RUN mkdir /gopath
ENV GOPATH=/gopath
     
ADD backend /gopath/src/github.com/foo/bar/backend
...

@djtm
Copy link

djtm commented Jul 7, 2018

@ralfthewise: Thanks a lot! Did you get it to work with minimal images?

FROM golang:1.9-alpine AS builder
...
FROM alpine
COPY --from=builder /gopath/...backend/ /gopath/...backend/
COPY --from=builder /usr/local/go/ /go/
RUN mkdir -p /usr/local && ln -s /go /usr/local/go

Still getting the same error however...

@notzippy
Copy link
Collaborator

notzippy commented Nov 2, 2018

Hi guys, sorry this fell through the cracks - is this still an issue in the later builds ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants