From f3545e798ed8e4cce941d93e35f41f587f5cf7f7 Mon Sep 17 00:00:00 2001 From: elpatron Date: Sun, 22 Mar 2026 13:28:53 +0100 Subject: [PATCH] perf(radio): reuse shared HTTP client for Radio Browser API - #5239 Use a package-level http.Client for connection reuse instead of allocating a new client on every get(). Signed-off-by: elpatron --- server/radiobrowser/radiobrowser.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/radiobrowser/radiobrowser.go b/server/radiobrowser/radiobrowser.go index a962947a8..03da2d1b9 100644 --- a/server/radiobrowser/radiobrowser.go +++ b/server/radiobrowser/radiobrowser.go @@ -152,9 +152,11 @@ func NotifyClick(ctx context.Context, streamURL string) { _, _ = get(ctx, path) } +// Shared client for Radio Browser requests: safe for concurrent use and reuses TCP connections. +var apiHTTPClient = &http.Client{Timeout: 20 * time.Second} + func get(ctx context.Context, path string) ([]byte, error) { hosts := shuffleHosts(APIHosts()) - client := &http.Client{Timeout: 20 * time.Second} var lastErr error for _, host := range hosts { reqURL := "https://" + host + path @@ -165,7 +167,7 @@ func get(ctx context.Context, path string) ([]byte, error) { } req.Header.Set("User-Agent", consts.HTTPUserAgent) - resp, err := client.Do(req) + resp, err := apiHTTPClient.Do(req) if err != nil { lastErr = err continue