From 4a3594096bb56fd5430738f975d4f983fb716b8a Mon Sep 17 00:00:00 2001 From: Naoki Kosaka Date: Fri, 21 Feb 2020 18:38:41 +0900 Subject: [PATCH] Fix not closed http.client. --- go.mod | 4 ++-- worker/sender.go | 4 ++-- worker/worker.go | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index aef1924..6ab8587 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,10 @@ go 1.13 require ( github.com/RichardKnop/machinery v1.7.3 github.com/Songmu/go-httpdate v1.0.0 - github.com/go-redis/redis v6.15.6+incompatible + github.com/go-redis/redis v6.15.7+incompatible github.com/patrickmn/go-cache v2.1.0+incompatible github.com/satori/go.uuid v1.2.0 - github.com/spf13/cobra v0.0.5 + github.com/spf13/cobra v0.0.6 github.com/spf13/viper v1.6.2 github.com/yukimochi/httpsig v0.1.3 ) diff --git a/worker/sender.go b/worker/sender.go index 95c29a2..8028902 100644 --- a/worker/sender.go +++ b/worker/sender.go @@ -39,11 +39,11 @@ func sendActivity(inboxURL string, KeyID string, body []byte, publicKey *rsa.Pri req.Header.Set("User-Agent", fmt.Sprintf("%s (golang net/http; Activity-Relay %s; %s)", viper.GetString("relay_servicename"), version, hostURL.Host)) req.Header.Set("Date", httpdate.Time2Str(time.Now())) appendSignature(req, &body, KeyID, publicKey) - client := &http.Client{Timeout: time.Duration(5) * time.Second} - resp, err := client.Do(req) + resp, err := httpClient.Do(req) if err != nil { return err } + defer resp.Body.Close() fmt.Println(inboxURL, resp.StatusCode) if resp.StatusCode/100 != 2 { diff --git a/worker/worker.go b/worker/worker.go index b9f9684..633a231 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -3,6 +3,7 @@ package main import ( "crypto/rsa" "fmt" + "net/http" "net/url" "os" "time" @@ -27,6 +28,7 @@ var ( hostPrivatekey *rsa.PrivateKey redisClient *redis.Client machineryServer *machinery.Server + httpClient *http.Client ) func relayActivity(args ...string) error { @@ -85,6 +87,7 @@ func initConfig() { if err != nil { panic(err) } + httpClient = &http.Client{Timeout: time.Duration(5) * time.Second} Actor.GenerateSelfKey(hostURL, &hostPrivatekey.PublicKey) newNullLogger := NewNullLogger()