Skip to content

apiserver still eats panic #30305

Closed
Closed
@xiang90

Description

We try to stop everything from eating panics here: #28800.

But API server still eats panics since the HTTP Server catches panics.

See this example:

package main

import (
    "fmt"
    "log"
    "net/http"
)

func main() {
    http.HandleFunc("/panic", func(w http.ResponseWriter, r *http.Request) {
        defer func() {
            if r := recover(); r != nil {
                fmt.Println("handle panic")
                panic(r)
            }
        }()

        fmt.Fprintf(w, "panic")
        panic("panic")
    })

    log.Fatal(http.ListenAndServe(":8080", nil))
}
handle panic
2016/08/09 11:12:51 http: panic serving 127.0.0.1:61476: panic
goroutine 20 [running]:
net/http.(*conn).serve.func1(0xc820086200)
    /usr/local/go/src/net/http/server.go:1389 +0xc1
panic(0x28bca0, 0xc82006eee0)
    /usr/local/go/src/runtime/panic.go:426 +0x4e9
main.main.func1.1()
    /Users/xiangli/playground/panic.go:14 +0x121
panic(0x28bca0, 0xc82006eee0)
    /usr/local/go/src/runtime/panic.go:426 +0x4e9
main.main.func1(0x7857a8, 0xc8200756c0, 0xc8200ec1c0)
    /Users/xiangli/playground/panic.go:19 +0xee
net/http.HandlerFunc.ServeHTTP(0x4062c0, 0x7857a8, 0xc8200756c0, 0xc8200ec1c0)
    /usr/local/go/src/net/http/server.go:1618 +0x3a
net/http.(*ServeMux).ServeHTTP(0xc820072a80, 0x7857a8, 0xc8200756c0, 0xc8200ec1c0)
    /usr/local/go/src/net/http/server.go:1910 +0x17d
net/http.serverHandler.ServeHTTP(0xc820086080, 0x7857a8, 0xc8200756c0, 0xc8200ec1c0)
    /usr/local/go/src/net/http/server.go:2081 +0x19e
net/http.(*conn).serve(0xc820086200)
    /usr/local/go/src/net/http/server.go:1472 +0xf2e
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:2137 +0x44e
handle panic
2016/08/09 11:12:56 http: panic serving 127.0.0.1:61477: panic
goroutine 21 [running]:
net/http.(*conn).serve.func1(0xc820086380)
    /usr/local/go/src/net/http/server.go:1389 +0xc1
panic(0x28bca0, 0xc82006ef90)
    /usr/local/go/src/runtime/panic.go:426 +0x4e9
main.main.func1.1()
    /Users/xiangli/playground/panic.go:14 +0x121
panic(0x28bca0, 0xc82006ef90)
    /usr/local/go/src/runtime/panic.go:426 +0x4e9
main.main.func1(0x7857a8, 0xc820075790, 0xc8200ec2a0)
    /Users/xiangli/playground/panic.go:19 +0xee
net/http.HandlerFunc.ServeHTTP(0x4062c0, 0x7857a8, 0xc820075790, 0xc8200ec2a0)
    /usr/local/go/src/net/http/server.go:1618 +0x3a
net/http.(*ServeMux).ServeHTTP(0xc820072a80, 0x7857a8, 0xc820075790, 0xc8200ec2a0)
    /usr/local/go/src/net/http/server.go:1910 +0x17d
net/http.serverHandler.ServeHTTP(0xc820086080, 0x7857a8, 0xc820075790, 0xc8200ec2a0)
    /usr/local/go/src/net/http/server.go:2081 +0x19e
net/http.(*conn).serve(0xc820086380)
    /usr/local/go/src/net/http/server.go:1472 +0xf2e
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:2137 +0x44e
handle panic
2016/08/09 11:12:57 http: panic serving 127.0.0.1:61478: panic
goroutine 22 [running]:
net/http.(*conn).serve.func1(0xc820086480)
    /usr/local/go/src/net/http/server.go:1389 +0xc1
panic(0x28bca0, 0xc82006f020)
    /usr/local/go/src/runtime/panic.go:426 +0x4e9
main.main.func1.1()
    /Users/xiangli/playground/panic.go:14 +0x121
panic(0x28bca0, 0xc82006f020)
    /usr/local/go/src/runtime/panic.go:426 +0x4e9
main.main.func1(0x7857a8, 0xc820075930, 0xc8200ec380)
    /Users/xiangli/playground/panic.go:19 +0xee
net/http.HandlerFunc.ServeHTTP(0x4062c0, 0x7857a8, 0xc820075930, 0xc8200ec380)
    /usr/local/go/src/net/http/server.go:1618 +0x3a
net/http.(*ServeMux).ServeHTTP(0xc820072a80, 0x7857a8, 0xc820075930, 0xc8200ec380)
    /usr/local/go/src/net/http/server.go:1910 +0x17d
net/http.serverHandler.ServeHTTP(0xc820086080, 0x7857a8, 0xc820075930, 0xc8200ec380)
    /usr/local/go/src/net/http/server.go:2081 +0x19e
net/http.(*conn).serve(0xc820086480)
    /usr/local/go/src/net/http/server.go:1472 +0xf2e
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:2137 +0x44e

/cc @lavalamp @krousey

Metadata

Assignees

No one assigned

    Labels

    area/controller-managerlifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.sig/api-machineryCategorizes an issue or PR as relevant to SIG API Machinery.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions