Is the standard HTTP server panic-free?

Written by
Link to Post by 

There is a common fear among Go developers from a web request handler suddenly panicking and crashing the whole app. So much so that various packages exists that wrap HTTP handlers into a function that recovers from the panic and writes to the log file. Yet, I am questioning if this is all needed, because AFAIK, the standard HTTP server already does panic recovery:

“` func (c *conn) serve(ctx context.Context) {

c.remoteAddr = c.rwc.RemoteAddr().String() ctx = context.WithValue(ctx, LocalAddrContextKey, c.rwc.LocalAddr()) defer func() { if err := recover(); err != nil && err != ErrAbortHandler { const size = 64 << 10 buf := make([]byte, size) buf = buf[:runtime.Stack(buf, false)] c.server.logf("http: panic serving %v: %vn%s", c.remoteAddr, err, buf) } 


If this is already in place, why the extra panic protection? What else should I be afraid of?

submitted by /u/preslavrachev
[link] [comments]

Article Tags:
· ·
Article Categories:

Leave a Reply