Skip to content

Commit 1079ecd

Browse files
committed
Fixes issue with not reusing http client
1 parent d050bb6 commit 1079ecd

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
02/22/2025 - 1.1.2
2+
==================
3+
- Fixed issue with creating new clients instead of reusing http client
4+
15
02/14/2024 - 1.1.1
26
==================
37
- Fixed issue where empty secrets causes configs to re-apply every checkin

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.1
1+
1.1.2

docs/status-api/system.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Parameter | Default | Description
145145

146146
```
147147
{
148-
"version": "1.1.1"
148+
"version": "1.1.2"
149149
}
150150
```
151151

@@ -154,7 +154,7 @@ Parameter | Default | Description
154154
```
155155
{
156156
"exitcode": 0,
157-
"output": "OK - rcagent version is 1.1.1",
157+
"output": "OK - rcagent version is 1.1.2",
158158
"perfdata": "",
159159
"longoutput": ""
160160
}
@@ -163,5 +163,5 @@ Parameter | Default | Description
163163
=== "Plugin"
164164

165165
```
166-
OK - rcagent version is 1.1.1
166+
OK - rcagent version is 1.1.2
167167
```

internal/manager/common.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ type ConfigsData struct {
4545
Plugins map[string]string
4646
}
4747

48+
var client http.Client
49+
var dlClient http.Client
50+
4851
// Set up the manager connection
4952
func Run(restart chan<- struct{}) {
5053

@@ -92,6 +95,8 @@ func Sync(s, c bool) bool {
9295
// need to get a certificate we do that now.
9396
func Register() {
9497

98+
clientSetup()
99+
95100
// Skip registration if we aren't using the manager
96101
if !config.UsingManager() {
97102
return
@@ -174,6 +179,26 @@ func checkin() {
174179
}
175180
}
176181

182+
func clientSetup() {
183+
184+
// Set up HTTP client for downloads
185+
dlClient = http.Client{
186+
CheckRedirect: func(r *http.Request, via []*http.Request) error {
187+
r.URL.Opaque = r.URL.Path
188+
return nil
189+
},
190+
}
191+
192+
// Set up an HTTP client for manager, ignore invalid certs if we have the config option set
193+
if config.Settings.Manager.IgnoreCert {
194+
tr := http.DefaultTransport.(*http.Transport).Clone()
195+
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
196+
client = http.Client{Transport: tr}
197+
} else {
198+
client = http.Client{}
199+
}
200+
}
201+
177202
// Send a POST request
178203
func sendPost(path string, data map[string]string) ([]byte, error) {
179204

@@ -220,18 +245,11 @@ func downloadFile(name string, url string) error {
220245
}
221246
defer file.Close()
222247

223-
client := http.Client{
224-
CheckRedirect: func(r *http.Request, via []*http.Request) error {
225-
r.URL.Opaque = r.URL.Path
226-
return nil
227-
},
228-
}
229-
230248
if config.DebugMode {
231249
config.LogDebugf("Downloading: %s", url)
232250
}
233251

234-
resp, err := client.Get(url)
252+
resp, err := dlClient.Get(url)
235253
if err != nil {
236254
return err
237255
}
@@ -246,12 +264,6 @@ func getRequest(req *http.Request) ([]byte, error) {
246264
req.Header.Set("Content-Type", "application/json")
247265
req.Header.Add("X-API-Key", config.Settings.Manager.APIKey)
248266

249-
// Set up an HTTP client, ignore invalid certs if we have the config option set
250-
tr := &http.Transport{
251-
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.Settings.Manager.IgnoreCert},
252-
}
253-
client := &http.Client{Transport: tr}
254-
255267
resp, err := client.Do(req)
256268
if err != nil {
257269
return []byte{}, err

versioninfo.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"FileVersion": {
44
"Major": 1,
55
"Minor": 1,
6-
"Patch": 1,
6+
"Patch": 2,
77
"Build": 0
88
},
99
"ProductVersion": {
1010
"Major": 1,
1111
"Minor": 1,
12-
"Patch": 1,
12+
"Patch": 2,
1313
"Build": 0
1414
},
1515
"FileFlagsMask": "3f",
@@ -22,14 +22,14 @@
2222
"Comments": "",
2323
"CompanyName": "ReChecked",
2424
"FileDescription": "ReChecked system status and monitoring agent.",
25-
"FileVersion": "v1.1.1.0",
25+
"FileVersion": "v1.1.2.0",
2626
"InternalName": "rcagent.exe",
2727
"LegalCopyright": "(c) 2024 ReChecked",
2828
"LegalTrademarks": "",
2929
"OriginalFilename": "",
3030
"PrivateBuild": "",
3131
"ProductName": "ReChecked Agent",
32-
"ProductVersion": "v1.1.1.0",
32+
"ProductVersion": "v1.1.2.0",
3333
"SpecialBuild": ""
3434
},
3535
"VarFileInfo": {

0 commit comments

Comments
 (0)