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