Skip to content

Commit

Permalink
Fixes issue with not reusing http client
Browse files Browse the repository at this point in the history
  • Loading branch information
jomann09 committed Feb 23, 2024
1 parent d050bb6 commit 1079ecd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
02/22/2025 - 1.1.2
==================
- Fixed issue with creating new clients instead of reusing http client

02/14/2024 - 1.1.1
==================
- Fixed issue where empty secrets causes configs to re-apply every checkin
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
1.1.2
6 changes: 3 additions & 3 deletions docs/status-api/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Parameter | Default | Description

```
{
"version": "1.1.1"
"version": "1.1.2"
}
```

Expand All @@ -154,7 +154,7 @@ Parameter | Default | Description
```
{
"exitcode": 0,
"output": "OK - rcagent version is 1.1.1",
"output": "OK - rcagent version is 1.1.2",
"perfdata": "",
"longoutput": ""
}
Expand All @@ -163,5 +163,5 @@ Parameter | Default | Description
=== "Plugin"

```
OK - rcagent version is 1.1.1
OK - rcagent version is 1.1.2
```
40 changes: 26 additions & 14 deletions internal/manager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type ConfigsData struct {
Plugins map[string]string
}

var client http.Client
var dlClient http.Client

// Set up the manager connection
func Run(restart chan<- struct{}) {

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

clientSetup()

// Skip registration if we aren't using the manager
if !config.UsingManager() {
return
Expand Down Expand Up @@ -174,6 +179,26 @@ func checkin() {
}
}

func clientSetup() {

// Set up HTTP client for downloads
dlClient = http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error {
r.URL.Opaque = r.URL.Path
return nil
},
}

// Set up an HTTP client for manager, ignore invalid certs if we have the config option set
if config.Settings.Manager.IgnoreCert {
tr := http.DefaultTransport.(*http.Transport).Clone()
tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
client = http.Client{Transport: tr}
} else {
client = http.Client{}
}
}

// Send a POST request
func sendPost(path string, data map[string]string) ([]byte, error) {

Expand Down Expand Up @@ -220,18 +245,11 @@ func downloadFile(name string, url string) error {
}
defer file.Close()

client := http.Client{
CheckRedirect: func(r *http.Request, via []*http.Request) error {
r.URL.Opaque = r.URL.Path
return nil
},
}

if config.DebugMode {
config.LogDebugf("Downloading: %s", url)
}

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

// Set up an HTTP client, ignore invalid certs if we have the config option set
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.Settings.Manager.IgnoreCert},
}
client := &http.Client{Transport: tr}

resp, err := client.Do(req)
if err != nil {
return []byte{}, err
Expand Down
8 changes: 4 additions & 4 deletions versioninfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"FileVersion": {
"Major": 1,
"Minor": 1,
"Patch": 1,
"Patch": 2,
"Build": 0
},
"ProductVersion": {
"Major": 1,
"Minor": 1,
"Patch": 1,
"Patch": 2,
"Build": 0
},
"FileFlagsMask": "3f",
Expand All @@ -22,14 +22,14 @@
"Comments": "",
"CompanyName": "ReChecked",
"FileDescription": "ReChecked system status and monitoring agent.",
"FileVersion": "v1.1.1.0",
"FileVersion": "v1.1.2.0",
"InternalName": "rcagent.exe",
"LegalCopyright": "(c) 2024 ReChecked",
"LegalTrademarks": "",
"OriginalFilename": "",
"PrivateBuild": "",
"ProductName": "ReChecked Agent",
"ProductVersion": "v1.1.1.0",
"ProductVersion": "v1.1.2.0",
"SpecialBuild": ""
},
"VarFileInfo": {
Expand Down

0 comments on commit 1079ecd

Please sign in to comment.