Skip to content

Commit b38b9ef

Browse files
anjannathopenshift-merge-robot
authored andcommitted
use http.Server with timeout instead of http.Serve
this change is same as what github.com/containers/gvisor-tap-vsock/pull/144 did for gvisor-tap-vsock golangci-lint complains about calling http.Serve that doesn't have any timeouts: cmd/crc/cmd/daemon.go:146:13: G114: Use of net/http serve function that has no support for setting timeouts (gosec) if err := http.Serve(listener, handlers.LoggingHandler(os.Stderr, mux)); err != nil { ^ cmd/crc/cmd/daemon.go:157:13: G114: Use of net/http serve function that has no support for setting timeouts (gosec) if err := http.Serve(ln, handlers.LoggingHandler(os.Stderr, mux)); err != nil { ^ cmd/crc/cmd/daemon.go:168:13: G114: Use of net/http serve function that has no support for setting timeouts (gosec) if err := http.Serve(networkListener, handlers.LoggingHandler(os.Stderr, mux)); err != nil { ^
1 parent 8793050 commit b38b9ef

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

cmd/crc/cmd/daemon.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ func run(configuration *types.Configuration) error {
146146
machineClient := newMachine()
147147
mux.Handle("/api/", http.StripPrefix("/api", api.NewMux(config, machineClient, logging.Memory, segmentClient)))
148148
mux.Handle("/socket/", http.StripPrefix("/socket", websocket.NewWebsocketServer(machineClient)))
149-
if err := http.Serve(listener, handlers.LoggingHandler(os.Stderr, mux)); err != nil {
149+
s := &http.Server{
150+
Handler: handlers.LoggingHandler(os.Stderr, mux),
151+
ReadTimeout: 10 * time.Second,
152+
WriteTimeout: 10 * time.Second,
153+
}
154+
if err := s.Serve(listener); err != nil {
150155
errCh <- errors.Wrap(err, "api http.Serve failed")
151156
}
152157
}()
@@ -157,7 +162,12 @@ func run(configuration *types.Configuration) error {
157162
}
158163
go func() {
159164
mux := gatewayAPIMux()
160-
if err := http.Serve(ln, handlers.LoggingHandler(os.Stderr, mux)); err != nil {
165+
s := &http.Server{
166+
Handler: handlers.LoggingHandler(os.Stderr, mux),
167+
ReadTimeout: 10 * time.Second,
168+
WriteTimeout: 10 * time.Second,
169+
}
170+
if err := s.Serve(ln); err != nil {
161171
errCh <- errors.Wrap(err, "gateway http.Serve failed")
162172
}
163173
}()
@@ -168,15 +178,25 @@ func run(configuration *types.Configuration) error {
168178
}
169179
go func() {
170180
mux := networkAPIMux(vn)
171-
if err := http.Serve(networkListener, handlers.LoggingHandler(os.Stderr, mux)); err != nil {
181+
s := &http.Server{
182+
Handler: handlers.LoggingHandler(os.Stderr, mux),
183+
ReadTimeout: 10 * time.Second,
184+
WriteTimeout: 10 * time.Second,
185+
}
186+
if err := s.Serve(networkListener); err != nil {
172187
errCh <- errors.Wrap(err, "host virtual IP http.Serve failed")
173188
}
174189
}()
175190

176191
go func() {
177192
mux := http.NewServeMux()
178193
mux.Handle(types.ConnectPath, vn.Mux())
179-
if err := http.Serve(vsockListener, mux); err != nil {
194+
s := &http.Server{
195+
Handler: mux,
196+
ReadTimeout: 10 * time.Second,
197+
WriteTimeout: 10 * time.Second,
198+
}
199+
if err := s.Serve(vsockListener); err != nil {
180200
errCh <- errors.Wrap(err, "virtualnetwork http.Serve failed")
181201
}
182202
}()

0 commit comments

Comments
 (0)