server: Don't recover from panics
This commit is contained in:
parent
a606c4fcc0
commit
bb444fb364
@ -21,12 +21,6 @@ var (
|
||||
// methods after a call to Shutdown or Close.
|
||||
ErrServerClosed = errors.New("gemini: server closed")
|
||||
|
||||
// ErrAbortHandler is a sentinel panic value to abort a handler.
|
||||
// While any panic from ServeGemini aborts the response to the client,
|
||||
// panicking with ErrAbortHandler also suppresses logging of a stack
|
||||
// trace to the server's error log.
|
||||
ErrAbortHandler = errors.New("gemini: abort Handler")
|
||||
|
||||
// ErrHandlerTimeout is returned on ResponseWriter Write calls
|
||||
// in handlers which have timed out.
|
||||
ErrHandlerTimeout = errors.New("gemini: Handler timeout")
|
||||
|
@ -14,13 +14,6 @@ import (
|
||||
// of the ServeGemini call.
|
||||
//
|
||||
// Handlers should not modify the provided Request.
|
||||
//
|
||||
// If ServeGemini panics, the server (the caller of ServeGemini) assumes that
|
||||
// the effect of the panic was isolated to the active request. It recovers
|
||||
// the panic, logs a stack trace to the server error log, and closes the
|
||||
// network connection. To abort a handler so the client sees an interrupted
|
||||
// response but the server doesn't log an error, panic with the value
|
||||
// ErrAbortHandler.
|
||||
type Handler interface {
|
||||
ServeGemini(context.Context, ResponseWriter, *Request)
|
||||
}
|
||||
|
10
server.go
10
server.go
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
"net"
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -298,15 +297,6 @@ func (srv *Server) serveConn(ctx context.Context, conn net.Conn) {
|
||||
defer srv.tryFinishShutdown()
|
||||
defer srv.deleteConn(&conn)
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil && err != ErrAbortHandler {
|
||||
const size = 64 << 10
|
||||
buf := make([]byte, size)
|
||||
buf = buf[:runtime.Stack(buf, false)]
|
||||
srv.logf("gemini: panic serving %v: %v\n%s", conn.RemoteAddr(), err, buf)
|
||||
}
|
||||
}()
|
||||
|
||||
if d := srv.ReadTimeout; d != 0 {
|
||||
conn.SetReadDeadline(time.Now().Add(d))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user