From 9d351c6a1262f4699722eb6b28dde222ffcabdd5 Mon Sep 17 00:00:00 2001 From: User Date: Sat, 7 Mar 2026 23:14:14 +0530 Subject: [PATCH] fix: reduce analytics timeout to 2 seconds (#511) Fixes slow exit issue where `doppler secrets get` waits 5-10 seconds before exiting. Analytics requests now timeout after 2 seconds instead of 10 seconds, significantly improving command responsiveness. The root cause was that analytics requests used the default 10-second HTTP timeout and the main program waited for the analytics goroutine to complete via WaitGroup before exiting. This meant any delay in the analytics server response would block command exit. Changes: - Add AnalyticsTimeoutDuration constant (2 seconds) - Use shorter timeout specifically for analytics requests - Analytics failures don't block command execution Fixes #511 --- pkg/http/analytics.go | 10 ++++++++++ pkg/http/config.go | 3 +++ 2 files changed, 13 insertions(+) diff --git a/pkg/http/analytics.go b/pkg/http/analytics.go index 955285fe..f81eadde 100644 --- a/pkg/http/analytics.go +++ b/pkg/http/analytics.go @@ -36,6 +36,11 @@ func CaptureCommand(command string) ([]byte, Error) { return nil, Error{Err: err, Message: "Unable to generate url"} } + // Use shorter timeout for analytics to avoid blocking command execution + originalTimeout := TimeoutDuration + TimeoutDuration = AnalyticsTimeoutDuration + defer func() { TimeoutDuration = originalTimeout }() + _, _, resp, err := PostRequest(url, true, map[string]string{"Content-Type": "application/json"}, body) if err != nil { return nil, Error{Err: err, Message: "Unable to send anonymous analytics"} @@ -60,6 +65,11 @@ func CaptureEvent(event string, metadata map[string]interface{}) ([]byte, Error) return nil, Error{Err: err, Message: "Unable to generate url"} } + // Use shorter timeout for analytics to avoid blocking command execution + originalTimeout := TimeoutDuration + TimeoutDuration = AnalyticsTimeoutDuration + defer func() { TimeoutDuration = originalTimeout }() + _, _, resp, err := PostRequest(url, true, map[string]string{"Content-Type": "application/json"}, body) if err != nil { return nil, Error{Err: err, Message: "Unable to send anonymous analytics"} diff --git a/pkg/http/config.go b/pkg/http/config.go index 990d7863..89ae8670 100644 --- a/pkg/http/config.go +++ b/pkg/http/config.go @@ -23,5 +23,8 @@ var UseTimeout = true // TimeoutDuration how long to wait for a request to complete before timing out var TimeoutDuration = 10 * time.Second +// AnalyticsTimeoutDuration timeout for analytics requests (shorter to avoid blocking command execution) +var AnalyticsTimeoutDuration = 2 * time.Second + // RequestAttempts how many request attempts are made before giving up var RequestAttempts = 5