Make HTTP client timeout configurable via existing -t/--timeout flag - #98
Merged
Merged
Conversation
Previously the HTTP client used a hardcoded 5 second timeout, independent of the --timeout flag. This caused requests to fail whenever the SentinelOne API took longer than 5s to respond, regardless of the timeout configured by the user.
Member
|
Hi, thanks for the PR. Looks good, but you probably need to update the test cases as well. |
Contributor
Author
|
Hi. Good catch, thanks! Updated api/client_test.go to match the new NewClient signature. go test ./... passes locally now. |
Member
|
Thanks for the contribution. I'll try to create a new release soon. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The HTTP client used internally in
api/client.gohad a hardcoded timeoutof 5 seconds (
DefaultTimeout = 5), completely independent of the-t/--timeoutflag exposed via the go-check library (defaults to 30s).As soon as a request to the SentinelOne API takes longer than 5 seconds,
the check fails with:
...no matter what value is passed via
-t. We ran into this inproduction: our SentinelOne threats query started taking ~11-12s to
respond (confirmed independently via curl, which succeeded fine), while
the plugin kept failing every single time, since 11s > the hardcoded 5s.
Fix
api.NewClient()now takes an explicittimeout time.Durationparameter instead of relying on the hardcoded constant.
Config(incheck.go) gets aTimeout time.Durationfield, passedthrough to
api.NewClient().main.gosetsconfig.Timeoutfromplugin.Timeout(the existing-t/--timeoutflag) after parsing arguments.DefaultTimeout(5s) is kept as-is and only used as a fallback ifNewClientis called with a zero/negative duration.This is a minimal, behavior-preserving change: the effective default
timeout stays the same (30s from the existing flag default), but it's
now actually possible to tune it.
Testing
Verified locally against a real SentinelOne instance:
-t: succeeds (falls back to the default 30s, comfortablyabove the ~11s the API currently needs to respond).
-t 1: fails fast with a timeout error, confirming the flag nowactually controls the HTTP client timeout.