From 48a5d875c7132be3c06f522152bf56496f3ca3b7 Mon Sep 17 00:00:00 2001 From: Akmal Date: Mon, 15 Jul 2024 07:52:52 +0700 Subject: [PATCH] Recreate new client for every req in grid --- handlers/grid.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/handlers/grid.go b/handlers/grid.go index 0aaf8db..4b7b65d 100644 --- a/handlers/grid.go +++ b/handlers/grid.go @@ -6,7 +6,6 @@ import ( scraper "instafix/handlers/scraper" "io" "math" - "net" "net/http" "os" "path/filepath" @@ -20,15 +19,6 @@ import ( "golang.org/x/image/draw" ) -var transport = &http.Transport{ - DialContext: (&net.Dialer{ - Timeout: 5 * time.Second, - }).DialContext, - TLSHandshakeTimeout: 5 * time.Second, - ResponseHeaderTimeout: 5 * time.Second, - ExpectContinueTimeout: 1 * time.Second, - DisableKeepAlives: true, -} var timeout = 60 * time.Second // getHeight returns the height of the rows, imagesWH [w,h] @@ -162,12 +152,12 @@ func Grid(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { var wg sync.WaitGroup images := make([]image.Image, len(mediaURLs)) - client := http.Client{Transport: transport, Timeout: timeout} for i, mediaURL := range mediaURLs { wg.Add(1) go func(i int, url string) { defer wg.Done() + client := http.Client{Timeout: timeout} req, err := http.NewRequest(http.MethodGet, url, http.NoBody) if err != nil { return