From a47fd8f52816368d9116d511fcd5ec8b327d4837 Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Fri, 11 Sep 2020 00:39:05 +0100 Subject: [PATCH] Disable keep-alive for cloud-event connections Disable keep alive forces the HTTP client to drop the connection once a response is received. This avoids building up large numbers of idle connections and it fixes the immediate issue. After this we may want to see how to ensure we can re-use connection and also set and idle-connection timeout. Fixes #3190 (cherry picked from commit 7a9a85b4a6343056902f90d3e3b34e8eac3c1fb2) --- .../events/cloudevent/cloudeventclient.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/reconciler/events/cloudevent/cloudeventclient.go b/pkg/reconciler/events/cloudevent/cloudeventclient.go index 1cd69b16bfc..d191d972471 100644 --- a/pkg/reconciler/events/cloudevent/cloudeventclient.go +++ b/pkg/reconciler/events/cloudevent/cloudeventclient.go @@ -18,6 +18,7 @@ package cloudevent import ( "context" + "net/http" cloudevents "github.com/cloudevents/sdk-go/v2" "k8s.io/client-go/rest" @@ -35,11 +36,19 @@ type CECKey struct{} func withCloudEventClient(ctx context.Context, cfg *rest.Config) context.Context { logger := logging.FromContext(ctx) - p, err := cloudevents.NewHTTP() + // When KeepAlive is enabled the connections are not reused - see + // Bug https://github.com/tektoncd/pipeline/issues/3190. This causes the + // number of connections to keep growing, even if when we limit max idle + // connections in the transport. + // TODO(afrittoli) Re-enable keep alive and ensure connections are reused + // See feature https://github.com/tektoncd/pipeline/issues/3204 + var useOnceTransport http.RoundTripper = &http.Transport{ + DisableKeepAlives: true, + } + p, err := cloudevents.NewHTTP(cloudevents.WithRoundTripper(useOnceTransport)) if err != nil { logger.Panicf("Error creating the cloudevents http protocol: %s", err) - return ctx } cloudEventClient, err := cloudevents.NewClient(p, cloudevents.WithUUIDs(), cloudevents.WithTimeNow())