Fix not closed http.client.

This commit is contained in:
Naoki Kosaka 2020-02-21 18:38:41 +09:00
parent 66f5b5bb53
commit 4a3594096b
3 changed files with 7 additions and 4 deletions

4
go.mod
View File

@ -5,10 +5,10 @@ go 1.13
require ( require (
github.com/RichardKnop/machinery v1.7.3 github.com/RichardKnop/machinery v1.7.3
github.com/Songmu/go-httpdate v1.0.0 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/patrickmn/go-cache v2.1.0+incompatible
github.com/satori/go.uuid v1.2.0 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/spf13/viper v1.6.2
github.com/yukimochi/httpsig v0.1.3 github.com/yukimochi/httpsig v0.1.3
) )

View File

@ -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("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())) req.Header.Set("Date", httpdate.Time2Str(time.Now()))
appendSignature(req, &body, KeyID, publicKey) appendSignature(req, &body, KeyID, publicKey)
client := &http.Client{Timeout: time.Duration(5) * time.Second} resp, err := httpClient.Do(req)
resp, err := client.Do(req)
if err != nil { if err != nil {
return err return err
} }
defer resp.Body.Close()
fmt.Println(inboxURL, resp.StatusCode) fmt.Println(inboxURL, resp.StatusCode)
if resp.StatusCode/100 != 2 { if resp.StatusCode/100 != 2 {

View File

@ -3,6 +3,7 @@ package main
import ( import (
"crypto/rsa" "crypto/rsa"
"fmt" "fmt"
"net/http"
"net/url" "net/url"
"os" "os"
"time" "time"
@ -27,6 +28,7 @@ var (
hostPrivatekey *rsa.PrivateKey hostPrivatekey *rsa.PrivateKey
redisClient *redis.Client redisClient *redis.Client
machineryServer *machinery.Server machineryServer *machinery.Server
httpClient *http.Client
) )
func relayActivity(args ...string) error { func relayActivity(args ...string) error {
@ -85,6 +87,7 @@ func initConfig() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
httpClient = &http.Client{Timeout: time.Duration(5) * time.Second}
Actor.GenerateSelfKey(hostURL, &hostPrivatekey.PublicKey) Actor.GenerateSelfKey(hostURL, &hostPrivatekey.PublicKey)
newNullLogger := NewNullLogger() newNullLogger := NewNullLogger()