Commit 08fda79
committed
fix: handler panics were not handled correctly
The net/http pkg automatically recovers from panics inside of handlers,
and CaptureMetrics was unfortunately breaking this functionality by
executing hnd in a new goroutine.
This patch fixes the problem by using locks instead of channels.
Rant: IMHO the automatic recover functionality of net/http is an
absolute misfeature. It's basically "ON ERROR RESUME NEXT" from Visual
Basic, except worse, because it's implicitly enforced upon you.
The documentation excuses this behavior with the following comment:
> If ServeHTTP panics, the server (the caller of ServeHTTP) assumes that
> the effect of the panic was isolated to the active request.
However, IMO that's an entirely unreasonable assumption. Most http
handlers will have shared state, e.g. a *database/sql.DB.
Anyway ... I'm afraid that ship has long sailed.
Fixes felixge#21 parent a3dccdc commit 08fda79
2 files changed
Lines changed: 53 additions & 64 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | 29 | | |
39 | 30 | | |
40 | 31 | | |
41 | 32 | | |
42 | | - | |
43 | | - | |
| 33 | + | |
44 | 34 | | |
45 | 35 | | |
46 | 36 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | 37 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
64 | 43 | | |
65 | 44 | | |
66 | 45 | | |
67 | 46 | | |
68 | 47 | | |
69 | 48 | | |
70 | 49 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
78 | 54 | | |
79 | 55 | | |
80 | 56 | | |
81 | 57 | | |
82 | 58 | | |
83 | 59 | | |
84 | 60 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
92 | 65 | | |
93 | 66 | | |
94 | 67 | | |
95 | 68 | | |
96 | 69 | | |
97 | 70 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
115 | 74 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
11 | 21 | | |
12 | 22 | | |
13 | 23 | | |
14 | 24 | | |
15 | 25 | | |
| 26 | + | |
16 | 27 | | |
17 | 28 | | |
18 | 29 | | |
| |||
37 | 48 | | |
38 | 49 | | |
39 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
40 | 57 | | |
41 | 58 | | |
42 | | - | |
| 59 | + | |
43 | 60 | | |
44 | 61 | | |
45 | 62 | | |
| |||
48 | 65 | | |
49 | 66 | | |
50 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
51 | 71 | | |
52 | | - | |
| 72 | + | |
53 | 73 | | |
54 | 74 | | |
55 | 75 | | |
56 | 76 | | |
57 | | - | |
| 77 | + | |
58 | 78 | | |
59 | | - | |
| 79 | + | |
60 | 80 | | |
61 | | - | |
| 81 | + | |
62 | 82 | | |
63 | 83 | | |
64 | 84 | | |
65 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
0 commit comments