Skip to content

Commit e07ebbb

Browse files
committed
fix race conditions
1 parent 2f423f1 commit e07ebbb

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

internal/collector/otel_collector_plugin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ func (oc *Collector) Close(ctx context.Context) error {
217217
oc.service.Shutdown()
218218
oc.cancel()
219219

220-
settings := oc.config.Client.Backoff
220+
settings := *oc.config.Client.Backoff
221221
settings.MaxElapsedTime = maxTimeToWaitForShutdown
222-
err := backoff.WaitUntil(ctx, settings, func() error {
222+
err := backoff.WaitUntil(ctx, &settings, func() error {
223223
if oc.service.GetState() == otelcol.StateClosed {
224224
return nil
225225
}

internal/file/file_manager_service.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ func (fms *FileManagerService) UpdateOverview(
178178
return response, nil
179179
}
180180

181+
backoffSettings := fms.agentConfig.Client.Backoff
181182
response, err := backoff.RetryWithData(
182183
sendUpdateOverview,
183-
backoffHelpers.Context(backOffCtx, fms.agentConfig.Client.Backoff),
184+
backoffHelpers.Context(backOffCtx, backoffSettings),
184185
)
185186
if err != nil {
186187
return err

internal/watcher/instance/instance_watcher_service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ func (iw *InstanceWatcherService) checkForUpdates(
223223
iw.sendNginxConfigContextUpdate(newCtx, nginxConfigContext)
224224
iw.nginxConfigCache[nginxConfigContext.InstanceID] = nginxConfigContext
225225
proto.UpdateNginxInstanceRuntime(newInstance, nginxConfigContext)
226+
iw.cacheMutex.Lock()
226227
iw.instanceCache[newInstance.GetInstanceMeta().GetInstanceId()] = newInstance
228+
iw.cacheMutex.Unlock()
227229
}
228230
}
229231
}

internal/watcher/process/process_operator.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ package process
88
import (
99
"context"
1010
"strings"
11-
12-
"github.com/shirou/gopsutil/v4/process"
11+
"sync"
1312

1413
"github.com/nginx/agent/v3/pkg/nginxprocess"
14+
"github.com/shirou/gopsutil/v4/process"
1515
)
1616

1717
//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6@v6.8.1 -generate
@@ -94,6 +94,10 @@ func (pw *ProcessOperator) Process(ctx context.Context, pid int32) (*nginxproces
9494
}
9595

9696
func convertProcess(ctx context.Context, proc *process.Process) *nginxprocess.Process {
97+
mu := &sync.Mutex{}
98+
99+
mu.Lock()
100+
defer mu.Unlock()
97101
ppid, _ := proc.PpidWithContext(ctx)
98102
name, _ := proc.NameWithContext(ctx)
99103
cmd, _ := proc.CmdlineWithContext(ctx)

0 commit comments

Comments
 (0)