Skip to content

Commit 711c44e

Browse files
committed
Implement httpClientTimeout
1 parent 6fcc9d0 commit 711c44e

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

internal/agent/api/action_api.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ func (s *Server) handleYcrashForward(writer http.ResponseWriter, request *http.R
175175
fr.RequestURI = ""
176176
fr.Header.Del("ycrash-forward")
177177
fr.Close = true
178-
client := http.Client{}
178+
client := http.Client{
179+
Timeout: config.GlobalConfig.HttpClientTimeout,
180+
}
179181
r, err := client.Do(fr)
180182
if err != nil {
181183
resp.Code = -2

internal/agent/ondemand/ondemand.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ func RequestFin(endpoint string) (resp []byte, err error) {
995995
}
996996
httpClient := &http.Client{
997997
Transport: transport,
998+
Timeout: config.GlobalConfig.HttpClientTimeout,
998999
}
9991000
req, err := http.NewRequest("POST", endpoint, nil)
10001001
if err != nil {

internal/capture/healthcheck.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ func newHTTPClient() *http.Client {
150150
DisableKeepAlives: true,
151151
ForceAttemptHTTP2: true,
152152
},
153+
Timeout: config.GlobalConfig.HttpClientTimeout,
153154
}
154155
}
155156

internal/capture/post.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func PostCustomDataWithPositionFunc(endpoint, params string, file *os.File, posi
114114
}
115115
httpClient := &http.Client{
116116
Transport: transport,
117+
Timeout: config.GlobalConfig.HttpClientTimeout,
117118
}
118119
err = position(file)
119120
if err != nil {
@@ -169,6 +170,7 @@ func GetData(endpoint string) (msg string, ok bool) {
169170
}
170171
httpClient := &http.Client{
171172
Transport: transport,
173+
Timeout: config.GlobalConfig.HttpClientTimeout,
172174
}
173175
req, err := http.NewRequest("GET", endpoint, nil)
174176
if err != nil {

internal/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ type Options struct {
9393
// Extended Data
9494
EdScript string `yaml:"edScript" usage:"Extended Data: Path to a custom script that collects extended diagnostics data"`
9595
EdDataFolder string `yaml:"edDataFolder" usage:"Extended Data: Directory path where artifacts generated by (-edScript) will be stored and collected. WARNING: All existing files in this folder will be cleared before script execution"`
96+
97+
HttpClientTimeout time.Duration `yaml:"httpClientTimeout" usage:"HTTP client timeout for API requests (e.g., 1m, 30s). Default is 60 seconds."`
9698
}
9799

98100
type HealthChecks map[string]HealthCheck
@@ -174,6 +176,7 @@ func defaultConfig() Config {
174176
DeferDelete: true,
175177
AppLogLineCount: 10000,
176178
TDCaptureDuration: 0 * time.Second, // Setting here 0 seconds as default since handling it in jstack.go
179+
HttpClientTimeout: 60 * time.Second,
177180
},
178181
}
179182
}

0 commit comments

Comments
 (0)