diff --git a/changelog/issue-479.toml b/changelog/issue-479.toml new file mode 100644 index 0000000..b2b592f --- /dev/null +++ b/changelog/issue-479.toml @@ -0,0 +1,6 @@ +type = "fixed" +message = "Re-create HTTP connection to Graylog every 60 request loops to detect DNS changes." + +issues = ["479"] +pulls = [""] + diff --git a/services/periodicals.go b/services/periodicals.go index 8efa7fb..26d4225 100644 --- a/services/periodicals.go +++ b/services/periodicals.go @@ -29,25 +29,30 @@ import ( "github.com/Graylog2/collector-sidecar/logger" ) +const reCreateHttpConnEvery = 60 + var log = logger.Log() -var httpClient *http.Client func StartPeriodicals(context *context.Ctx) { - if httpClient == nil { - httpClient = rest.NewHTTPClient(api.GetTlsConfig(context)) - } go func() { + var httpClient *http.Client + configChecksums := make(map[string]string) var lastBackendResponse graylog.ResponseBackendList var lastRegResponse graylog.ResponseCollectorRegistration logOnce := true - firstRun := true + iteration := 0 + for { - if !firstRun { + if iteration > 0 { time.Sleep(time.Duration(context.UserConfig.UpdateInterval) * time.Second) } - firstRun = false + // Re-create HTTP connection every X loops: https://github.com/Graylog2/collector-sidecar/issues/479 + if iteration%reCreateHttpConnEvery == 0 { + httpClient = rest.NewHTTPClient(api.GetTlsConfig(context)) + } + iteration++ serverVersion, err := api.GetServerVersion(httpClient, context) if err != nil {