Skip to content

Commit a5420c6

Browse files
author
Monokaix
committed
Add http server timeout
Signed-off-by: Monokaix <[email protected]>
1 parent 2bd5be7 commit a5420c6

File tree

10 files changed

+45
-13
lines changed

10 files changed

+45
-13
lines changed

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("", "")

config/crd/volcano/bases/scheduling.volcano.sh_queues.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ spec:
153153
description: Type define the type of queue
154154
type: string
155155
weight:
156+
default: 1
156157
format: int32
158+
maximum: 65535
159+
minimum: 1
157160
type: integer
158161
type: object
159162
status:

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-0.20250326062604-2d1b261f52f1
49+
volcano.sh/apis v1.11.1-0.20250423093821-61bafe877200
5050
)
5151

5252
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,5 +511,5 @@ sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
511511
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
512512
stathat.com/c/consistent v1.0.0 h1:ezyc51EGcRPJUxfHGSgJjWzJdj3NiMU9pNfLNGiXV0c=
513513
stathat.com/c/consistent v1.0.0/go.mod h1:QkzMWzcbB+yQBL2AttO6sgsQS/JSTapcDISJalmCDS0=
514-
volcano.sh/apis v1.11.1-0.20250326062604-2d1b261f52f1 h1:fvtSPUgw7XlmqvvFH9AGCZfR9KXo6qFeWee2PoechIw=
515-
volcano.sh/apis v1.11.1-0.20250326062604-2d1b261f52f1/go.mod h1:0XNNnIOevJSYNiXRmwhXUrYCcCcWcBeTY0nxrlkk03A=
514+
volcano.sh/apis v1.11.1-0.20250423093821-61bafe877200 h1:O5khbEoLxwLBcoQRE6jsax8kAVMSNj1qPDLdPoEcaek=
515+
volcano.sh/apis v1.11.1-0.20250423093821-61bafe877200/go.mod h1:0XNNnIOevJSYNiXRmwhXUrYCcCcWcBeTY0nxrlkk03A=

installer/helm/chart/volcano/crd/bases/scheduling.volcano.sh_queues.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ spec:
152152
description: Type define the type of queue
153153
type: string
154154
weight:
155+
default: 1
155156
format: int32
157+
maximum: 65535
158+
minimum: 1
156159
type: integer
157160
type: object
158161
status:

installer/volcano-development.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5016,7 +5016,10 @@ spec:
50165016
description: Type define the type of queue
50175017
type: string
50185018
weight:
5019+
default: 1
50195020
format: int32
5021+
maximum: 65535
5022+
minimum: 1
50205023
type: integer
50215024
type: object
50225025
status:

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)