From 1abd82aa811e1f08ba3c3646fea95608ac519c17 Mon Sep 17 00:00:00 2001 From: Knative Prow Robot Date: Fri, 24 Nov 2023 06:50:35 +0000 Subject: [PATCH] [release-1.12] Add timeouts on receive adapter (#447) * Update adapter.go * Update adapter.go * Update adapter.go * Update adapter.go --------- Co-authored-by: David Hadas --- pkg/adapter/adapter.go | 7 +++++-- pkg/mtadapter/adapter.go | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/adapter/adapter.go b/pkg/adapter/adapter.go index cd1485820..243e4108a 100644 --- a/pkg/adapter/adapter.go +++ b/pkg/adapter/adapter.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "net/http" + "time" cloudevents "github.com/cloudevents/sdk-go/v2" "go.uber.org/zap" @@ -79,8 +80,10 @@ func (a *gitHubAdapter) Start(ctx context.Context) error { done := make(chan bool, 1) server := &http.Server{ - Addr: ":" + a.port, - Handler: a.newRouter(), + ReadTimeout: 10 * time.Second, + ReadHeaderTimeout: 2 * time.Second, + Addr: ":" + a.port, + Handler: a.newRouter(), } go common.GracefulShutdown(server, a.logger, ctx.Done(), done) diff --git a/pkg/mtadapter/adapter.go b/pkg/mtadapter/adapter.go index b9cc1020a..6bf8872c5 100644 --- a/pkg/mtadapter/adapter.go +++ b/pkg/mtadapter/adapter.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "net/http" + "time" cloudevents "github.com/cloudevents/sdk-go/v2" "go.uber.org/zap" @@ -87,8 +88,10 @@ func NewAdapter(ctx context.Context, processed adapter.EnvConfigAccessor, ceClie func (a *gitHubAdapter) Start(ctx context.Context) error { // Start our multi-tenant server receiving GitHub events server := &http.Server{ - Addr: fmt.Sprintf(":%d", a.port), - Handler: a.router, + ReadTimeout: 10 * time.Second, + ReadHeaderTimeout: 2 * time.Second, + Addr: fmt.Sprintf(":%d", a.port), + Handler: a.router, } done := make(chan bool, 1)