Comments (5)
I am using the runtime.Callers
to get stack info, hope this helps.
callers := make([]uintptr, 10)
num := runtime.Callers(0, callers)
frames := runtime.CallersFrames(callers)
var (
frame runtime.Frame
more bool
)
for {
frame, more = frames.Next();
fmt.Println(frame.File, frame.Line)
num--
if !more || num <= 0 {
break
}
}
from fasthttprouter.
PanicHandler
really need improvements. You can try @ruishengyang 's solution temporarily.
from fasthttprouter.
Hi @devghosh , I test in my codes:
func apiServerPanic(ctx *fasthttp.RequestCtx, rcv interface{}) {
log.Printf("server panic: %+v\n%s", rcv, debug.Stack())
msg := fmt.Sprintf("server painc: %v\n", rcv)
ctx.Write([]byte(msg))
ctx.Write(debug.Stack())
ctx.SetStatusCode(500)
return
}
...
router.PanicHandler = apiServerPanic
And server successfully log and return the right stack:
server painc: runtime error: index out of range
goroutine 6 [running]:
runtime/debug.Stack(0xc420184000, 0xc420016420, 0x30)
/usr/local/opt/go/libexec/src/runtime/debug/stack.go:24 +0x79
bdn/server.apiServerPanic(0xc420184000, 0x2d0420, 0xc4200140f0)
/Users/zippo/develop/go/src/bdn/server/server.go:73 +0x1cd
github.com/buaazp/fasthttprouter.(*Router).recv(0xc4201568d0, 0xc420184000)
/Users/zippo/develop/go/src/github.com/buaazp/fasthttprouter/router.go:236 +0x5b
panic(0x2d0420, 0xc4200140f0)
/usr/local/opt/go/libexec/src/runtime/panic.go:458 +0x243
bdn/util.FastItWorks(0xc420184000)
/Users/zippo/develop/go/src/bdn/util/http.go:233 +0x14
github.com/buaazp/fasthttprouter.(*Router).Handler(0xc4201568d0, 0xc420184000)
/Users/zippo/develop/go/src/github.com/buaazp/fasthttprouter/router.go:300 +0xad5
bdn/util.FastLogger.func1(0xc420184000)
/Users/zippo/develop/go/src/bdn/util/logger.go:30 +0x20b
github.com/valyala/fasthttp.(*Server).serveConn(0xc420067d40, 0x48c260, 0xc42002e010, 0x1, 0x101)
/Users/zippo/develop/go/src/github.com/valyala/fasthttp/server.go:1533 +0x573
github.com/valyala/fasthttp.(*Server).(github.com/valyala/fasthttp.serveConn)-fm(0x48c260, 0xc42002e010, 0xc42002bf58, 0x1)
/Users/zippo/develop/go/src/github.com/valyala/fasthttp/server.go:1250 +0x3e
github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc420170080, 0xc42000c400)
/Users/zippo/develop/go/src/github.com/valyala/fasthttp/workerpool.go:210 +0xde
github.com/valyala/fasthttp.(*workerPool).getCh.func1(0xc420170080, 0xc42000c400, 0x2aa4a0, 0xc42000c400)
/Users/zippo/develop/go/src/github.com/valyala/fasthttp/workerpool.go:182 +0x35
created by github.com/valyala/fasthttp.(*workerPool).getCh
/Users/zippo/develop/go/src/github.com/valyala/fasthttp/workerpool.go:184 +0x111
Can you show me the only fasthttp stack
you mentioned?
from fasthttprouter.
Hi, @buaazp thanks for the reply, please see the stack trace
runtime/debug.Stack(0x42e660, 0x2f, 0x0)
/usr/local/go/src/runtime/debug/stack.go:24 +0x79
bitbucket.org/externalproject/session-service/routes.glob..func1(0xc42011ed80, 0x6ffe60, 0xc42000c130)
/home/project/go/src/github.com/project/myproject/_libs/src/bitbucket.org/externalproject/session-service/routes/route_manager.go:22 +0x34
github.com/buaazp/fasthttprouter.(*Router).recv(0xc420170270, 0xc42011ed80)
/home/project/go/src/github.com/project/myproject/_libs/src/github.com/buaazp/fasthttprouter/router.go:236 +0x5b
panic(0x6ffe60, 0xc42000c130)
/usr/local/go/src/runtime/panic.go:458 +0x243
github.com/valyala/fasthttp.(*RequestCtx).SetUserValue(0x0, 0x76dcd7, 0x2, 0x6e87e0, 0xc420149650)
/home/project/go/src/github.com/project/myproject/_libs/src/github.com/valyala/fasthttp/server.go:461 +0x22
github.com/buaazp/fasthttprouter.(*node).getValue(0xc420015680, 0xc420013127, 0xb, 0x0, 0xc4200feb20, 0x7300000000)
/home/project/go/src/github.com/project/myproject/_libs/src/github.com/buaazp/fasthttprouter/tree.go:364 +0x1c7
github.com/buaazp/fasthttprouter.(*Router).allowed(0xc420170270, 0xc420013100, 0x32, 0xc42003fc48, 0x3, 0x25, 0x33)
/home/project/go/src/github.com/project/myproject/_libs/src/github.com/buaazp/fasthttprouter/router.go:273 +0x13d
github.com/buaazp/fasthttprouter.(*Router).Handler(0xc420170270, 0xc42011ed80)
/home/project/go/src/github.com/project/myproject/_libs/src/github.com/buaazp/fasthttprouter/router.go:353 +0x23e
github.com/buaazp/fasthttprouter.(*Router).Handler-fm(0xc42011ed80)
Note: I have used externalproject
and fasthttp
both as dependency in project
Panic started at some function f1() but stack trace shows only two stack line of my project and it does not contain file containing f1()
bitbucket.org/externalproject/session-service/routes.glob..func1(0xc42011ed80, 0x6ffe60, 0xc42000c130)
/home/project/go/src/github.com/project/myproject/_libs/src/bitbucket.org/externalproject/session-service/routes/route_manager.go:22 +0x34
from fasthttprouter.
Maybe your fasthttprouter
code is not latest. Pull the latest codes in master branch and try again.
from fasthttprouter.
Related Issues (20)
- random fail response from server HOT 4
- Router allocates on the heap HOT 1
- Is it willing to support the sub-router? HOT 1
- Handling subdomains HOT 1
- JWT middleware support HOT 3
- file server HOT 2
- go1.9后net/http比fasthttp 慢多少呢?
- Static files from root
- Add Group and Middleware support HOT 2
- Parameters as request instead of endpoint url HOT 10
- wildcard route ':slug' conflicts with existing children HOT 2
- Integrate with gorilla/websocket HOT 1
- Recognize defined path in handler HOT 1
- REPO HAS MOVED HOT 5
- How to init fake RequestCtx for unit test's? HOT 1
- don't concern about method HOT 1
- How to make ReverseProxy on fasthttprouter HOT 1
- Sir, how do I set the maximum file upload size? HOT 1
- Abandoned. Use fasthttp/router instead. HOT 1
- How to update a route path? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fasthttprouter.