@@ -148,6 +148,7 @@ func (c *HealthServerConfig) AddLivezChecks(checks ...healthz.HealthChecker) {
148
148
// HealthServer is an HTTP server with healthz capabilities.
149
149
type HealthServer struct {
150
150
srv * Server
151
+ mux * http.ServeMux
151
152
152
153
shudownCh chan struct {}
153
154
@@ -165,10 +166,15 @@ type HealthServer struct {
165
166
166
167
// NewHealthServer returns an HTTP server with healthz capabilities.
167
168
func NewHealthServer (ctx context.Context , cfg HealthServerConfig , opts ... SrvOptFunc ) * HealthServer {
168
- srv := NewServer (ctx , cfg .Addr , cfg .Handler , opts ... )
169
+ // Setup the mux early so H2C can attach properly.
170
+ mux := http .NewServeMux ()
171
+ mux .Handle ("/" , cfg .Handler )
172
+
173
+ srv := NewServer (ctx , cfg .Addr , mux , opts ... )
169
174
170
175
return & HealthServer {
171
176
srv : srv ,
177
+ mux : mux ,
172
178
shudownCh : make (chan struct {}),
173
179
readyzChecks : cfg .ReadyzChecks ,
174
180
livezChecks : cfg .LivezChecks ,
@@ -215,17 +221,13 @@ func (s *HealthServer) Serve(errFn func(error)) {
215
221
}
216
222
217
223
func (s * HealthServer ) installChecks () {
218
- mux := http .NewServeMux ()
219
- s .installLivezChecks (mux )
224
+ s .installLivezChecks (s .mux )
220
225
221
226
// When shutdown is started, the readyz check should start failing.
222
227
if err := s .AddReadyzChecks (shutdownCheck {ch : s .shudownCh }); err != nil {
223
228
s .log .Error ("Could not install readyz shutdown check" , lctx .Err (err ))
224
229
}
225
- s .installReadyzChecks (mux )
226
-
227
- mux .Handle ("/" , s .srv .srv .Handler )
228
- s .srv .srv .Handler = mux
230
+ s .installReadyzChecks (s .mux )
229
231
}
230
232
231
233
func (s * HealthServer ) installReadyzChecks (mux * http.ServeMux ) {
0 commit comments