@@ -2438,6 +2438,14 @@ func TestTimeoutHandlerEmptyResponse(t *testing.T) {
2438
2438
}
2439
2439
}
2440
2440
2441
+ // https://golang.org/issues/22084
2442
+ func TestTimeoutHandlerPanicRecovery (t * testing.T ) {
2443
+ wrapper := func (h Handler ) Handler {
2444
+ return TimeoutHandler (h , time .Second , "" )
2445
+ }
2446
+ testHandlerPanic (t , false , false , wrapper , "intentional death for testing" )
2447
+ }
2448
+
2441
2449
func TestRedirectBadPath (t * testing.T ) {
2442
2450
// This used to crash. It's not valid input (bad path), but it
2443
2451
// shouldn't crash.
@@ -2551,22 +2559,22 @@ func testZeroLengthPostAndResponse(t *testing.T, h2 bool) {
2551
2559
}
2552
2560
}
2553
2561
2554
- func TestHandlerPanicNil_h1 (t * testing.T ) { testHandlerPanic (t , false , h1Mode , nil ) }
2555
- func TestHandlerPanicNil_h2 (t * testing.T ) { testHandlerPanic (t , false , h2Mode , nil ) }
2562
+ func TestHandlerPanicNil_h1 (t * testing.T ) { testHandlerPanic (t , false , h1Mode , nil , nil ) }
2563
+ func TestHandlerPanicNil_h2 (t * testing.T ) { testHandlerPanic (t , false , h2Mode , nil , nil ) }
2556
2564
2557
2565
func TestHandlerPanic_h1 (t * testing.T ) {
2558
- testHandlerPanic (t , false , h1Mode , "intentional death for testing" )
2566
+ testHandlerPanic (t , false , h1Mode , nil , "intentional death for testing" )
2559
2567
}
2560
2568
func TestHandlerPanic_h2 (t * testing.T ) {
2561
- testHandlerPanic (t , false , h2Mode , "intentional death for testing" )
2569
+ testHandlerPanic (t , false , h2Mode , nil , "intentional death for testing" )
2562
2570
}
2563
2571
2564
2572
func TestHandlerPanicWithHijack (t * testing.T ) {
2565
2573
// Only testing HTTP/1, and our http2 server doesn't support hijacking.
2566
- testHandlerPanic (t , true , h1Mode , "intentional death for testing" )
2574
+ testHandlerPanic (t , true , h1Mode , nil , "intentional death for testing" )
2567
2575
}
2568
2576
2569
- func testHandlerPanic (t * testing.T , withHijack , h2 bool , panicValue interface {}) {
2577
+ func testHandlerPanic (t * testing.T , withHijack , h2 bool , wrapper func ( Handler ) Handler , panicValue interface {}) {
2570
2578
defer afterTest (t )
2571
2579
// Unlike the other tests that set the log output to ioutil.Discard
2572
2580
// to quiet the output, this test uses a pipe. The pipe serves three
@@ -2589,7 +2597,7 @@ func testHandlerPanic(t *testing.T, withHijack, h2 bool, panicValue interface{})
2589
2597
defer log .SetOutput (os .Stderr )
2590
2598
defer pw .Close ()
2591
2599
2592
- cst := newClientServerTest ( t , h2 , HandlerFunc (func (w ResponseWriter , r * Request ) {
2600
+ var handler Handler = HandlerFunc (func (w ResponseWriter , r * Request ) {
2593
2601
if withHijack {
2594
2602
rwc , _ , err := w .(Hijacker ).Hijack ()
2595
2603
if err != nil {
@@ -2598,7 +2606,11 @@ func testHandlerPanic(t *testing.T, withHijack, h2 bool, panicValue interface{})
2598
2606
defer rwc .Close ()
2599
2607
}
2600
2608
panic (panicValue )
2601
- }))
2609
+ })
2610
+ if wrapper != nil {
2611
+ handler = wrapper (handler )
2612
+ }
2613
+ cst := newClientServerTest (t , h2 , handler )
2602
2614
defer cst .close ()
2603
2615
2604
2616
// Do a blocking read on the log output pipe so its logging
0 commit comments