From e43c316f6cdf2473d2cd873340baa4143a5ed1ae Mon Sep 17 00:00:00 2001 From: Dat Truong Date: Wed, 15 May 2019 20:22:54 +0200 Subject: [PATCH] Set timeout and and connection limit (#284) --- gateways/transformer.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gateways/transformer.go b/gateways/transformer.go index 1283fdbe52..eccb75cf7e 100644 --- a/gateways/transformer.go +++ b/gateways/transformer.go @@ -20,10 +20,12 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1" + "net" "net/http" "time" + "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1" + "github.com/argoproj/argo-events/common" apicommon "github.com/argoproj/argo-events/pkg/apis/common" pc "github.com/argoproj/argo-events/pkg/apis/common" @@ -149,7 +151,17 @@ func (gc *GatewayConfig) postCloudEventToWatcher(host string, port string, endpo return err } req.Header.Set("Content-Type", "application/json") - client := &http.Client{} + + client := &http.Client{ + Timeout: 20 * time.Second, + Transport: &http.Transport{ + Dial: (&net.Dialer{ + KeepAlive: 600 * time.Second, + }).Dial, + MaxIdleConns: 100, + MaxIdleConnsPerHost: 50, + }, + } _, err = client.Do(req) return err }