Skip to content

Commit c1b02e4

Browse files
committed
Create new mux (http.Handler) for each invocation
1 parent 5be5021 commit c1b02e4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

proxy/run.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ func Run(ctx context.Context, args []string) int {
182182
config.Bind = maybeAddPort(config.Bind, "9042")
183183
config.HttpBind = maybeAddPort(config.HttpBind, "8000")
184184

185-
maybeAddHealthCheck(p)
185+
var mux http.ServeMux
186+
maybeAddHealthCheck(p, &mux)
186187

187-
err = listenAndServe(p, ctx, logger)
188+
err = listenAndServe(p, &mux, ctx, logger)
188189
if err != nil {
189190
cliCtx.Errorf("%v", err)
190191
return 1
@@ -213,13 +214,13 @@ func parseProtocolVersion(s string) (version primitive.ProtocolVersion, ok bool)
213214
}
214215

215216
// maybeAddHealthCheck checks the config and adds handlers for health checks if required.
216-
func maybeAddHealthCheck(p *Proxy) {
217+
func maybeAddHealthCheck(p *Proxy, mux *http.ServeMux) {
217218
if config.HealthCheck {
218-
http.HandleFunc(livenessPath, func(writer http.ResponseWriter, request *http.Request) {
219+
mux.HandleFunc(livenessPath, func(writer http.ResponseWriter, request *http.Request) {
219220
writer.WriteHeader(http.StatusOK)
220221
_, _ = writer.Write([]byte("ok"))
221222
})
222-
http.HandleFunc(readinessPath, func(writer http.ResponseWriter, request *http.Request) {
223+
mux.HandleFunc(readinessPath, func(writer http.ResponseWriter, request *http.Request) {
223224
header := writer.Header()
224225
header.Set("Content-Type", "application/json")
225226

@@ -252,11 +253,11 @@ func maybeAddPort(addr string, defaultPort string) string {
252253
}
253254

254255
// listenAndServe correctly handles serving both the proxy and an HTTP server simultaneously.
255-
func listenAndServe(p *Proxy, ctx context.Context, logger *zap.Logger) (err error) {
256+
func listenAndServe(p *Proxy, mux *http.ServeMux, ctx context.Context, logger *zap.Logger) (err error) {
256257
var wg sync.WaitGroup
257258

258259
ch := make(chan error)
259-
server := http.Server{Addr: config.HttpBind}
260+
server := http.Server{Addr: config.HttpBind, Handler: mux}
260261

261262
numServers := 1 // Without the HTTP server
262263

0 commit comments

Comments
 (0)