Skip to content

Commit 684aef1

Browse files
author
Monokaix
committed
Add http server timeout
Signed-off-by: Monokaix <[email protected]>
1 parent 8aa29a3 commit 684aef1

7 files changed

Lines changed: 36 additions & 13 deletions

File tree

cmd/agent/app/app.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/controller-manager/pkg/clientbuilder"
3333
"k8s.io/klog/v2"
3434

35+
"volcano.sh/apis/pkg/apis/helpers"
3536
"volcano.sh/volcano/cmd/agent/app/options"
3637
"volcano.sh/volcano/pkg/agent/healthcheck"
3738
"volcano.sh/volcano/pkg/agent/utils"
@@ -81,8 +82,11 @@ func RunServer(checker healthcheck.HealthChecker, address string, port int) {
8182
mux.HandleFunc("/healthz", checker.HealthCheck)
8283
mux.Handle("/metrics", promhttp.Handler())
8384
s := &http.Server{
84-
Addr: net.JoinHostPort(address, strconv.Itoa(port)),
85-
Handler: mux,
85+
Addr: net.JoinHostPort(address, strconv.Itoa(port)),
86+
Handler: mux,
87+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
88+
ReadTimeout: helpers.DefaultReadTimeout,
89+
WriteTimeout: helpers.DefaultWriteTimeout,
8690
}
8791
if err := s.ListenAndServe(); err != nil {
8892
klog.Fatalf("failed to start health check server: %v", err)

cmd/controller-manager/app/server.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,17 @@ func Run(opt *options.ServerOption) error {
5858

5959
if opt.EnableMetrics {
6060
go func() {
61-
http.Handle("/metrics", commonutil.PromHandler())
62-
klog.Fatalf("Prometheus Http Server failed %s", http.ListenAndServe(opt.ListenAddress, nil))
61+
mux := http.NewServeMux()
62+
mux.Handle("/metrics", commonutil.PromHandler())
63+
64+
server := &http.Server{
65+
Addr: opt.ListenAddress,
66+
Handler: mux,
67+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
68+
ReadTimeout: helpers.DefaultReadTimeout,
69+
WriteTimeout: helpers.DefaultWriteTimeout,
70+
}
71+
klog.Fatalf("Prometheus Http Server failed: %s", server.ListenAndServe())
6372
}()
6473
}
6574

cmd/scheduler/app/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"os"
2525

2626
"volcano.sh/apis/pkg/apis/helpers"
27-
2827
"volcano.sh/volcano/cmd/scheduler/app/options"
2928
"volcano.sh/volcano/pkg/kube"
3029
"volcano.sh/volcano/pkg/scheduler"
@@ -157,8 +156,11 @@ func startMetricsServer(opt *options.ServerOption) {
157156
}
158157

159158
server := &http.Server{
160-
Addr: opt.ListenAddress,
161-
Handler: mux,
159+
Addr: opt.ListenAddress,
160+
Handler: mux,
161+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
162+
ReadTimeout: helpers.DefaultReadTimeout,
163+
WriteTimeout: helpers.DefaultWriteTimeout,
162164
}
163165

164166
if err := server.ListenAndServe(); err != nil {

cmd/webhook-manager/app/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ func Run(config *options.Config) error {
108108
}
109109

110110
server := &http.Server{
111-
Addr: config.ListenAddress + ":" + strconv.Itoa(config.Port),
112-
TLSConfig: configTLS(config, restConfig),
111+
Addr: config.ListenAddress + ":" + strconv.Itoa(config.Port),
112+
TLSConfig: configTLS(config, restConfig),
113+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
114+
ReadTimeout: helpers.DefaultReadTimeout,
115+
WriteTimeout: helpers.DefaultWriteTimeout,
113116
}
114117
go func() {
115118
err = server.ListenAndServeTLS("", "")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
sigs.k8s.io/controller-runtime v0.13.0
4747
sigs.k8s.io/yaml v1.4.0
4848
stathat.com/c/consistent v1.0.0
49-
volcano.sh/apis v1.11.1
49+
volcano.sh/apis v1.11.2
5050
)
5151

5252
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,5 +510,5 @@ sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
510510
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
511511
stathat.com/c/consistent v1.0.0 h1:ezyc51EGcRPJUxfHGSgJjWzJdj3NiMU9pNfLNGiXV0c=
512512
stathat.com/c/consistent v1.0.0/go.mod h1:QkzMWzcbB+yQBL2AttO6sgsQS/JSTapcDISJalmCDS0=
513-
volcano.sh/apis v1.11.1 h1:BuewlHccLIJVJmVcBF32KewXJmtwpCjx4d7fxVxG900=
514-
volcano.sh/apis v1.11.1/go.mod h1:FOdmG++9+8lgENJ9XXDh+O3Jcb9YVRnlMSpgIh3NSVI=
513+
volcano.sh/apis v1.11.2 h1:Vz8NzP0af8vyxRccrEUt6/FikD5eeEOnCZRolVzZvK8=
514+
volcano.sh/apis v1.11.2/go.mod h1:FOdmG++9+8lgENJ9XXDh+O3Jcb9YVRnlMSpgIh3NSVI=

pkg/util/socket.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import (
3131
"golang.org/x/sys/unix"
3232
"k8s.io/apimachinery/pkg/util/runtime"
3333
"k8s.io/klog/v2"
34+
35+
"volcano.sh/apis/pkg/apis/helpers"
3436
)
3537

3638
const (
@@ -201,7 +203,10 @@ func listenUnix(componentName string, socketDir string) (net.Listener, error) {
201203
// serveOnListener starts the server using given listener, loops forever.
202204
func serveOnListener(l net.Listener, m *http.ServeMux) error {
203205
server := http.Server{
204-
Handler: m,
206+
Handler: m,
207+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
208+
ReadTimeout: helpers.DefaultReadTimeout,
209+
WriteTimeout: helpers.DefaultWriteTimeout,
205210
}
206211
return server.Serve(l)
207212
}

0 commit comments

Comments
 (0)