Skip to content

Commit c031c41

Browse files
committed
fix test
1 parent 667a49a commit c031c41

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/watcher/instance/nginx-app-protect-instance-watcher.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"log/slog"
1111
"os"
1212
"strings"
13+
"sync"
1314
"time"
1415

1516
"github.com/fsnotify/fsnotify"
@@ -44,12 +45,14 @@ type NginxAppProtectInstanceWatcher struct {
4445
attackSignatureVersion string
4546
threatCampaignVersion string
4647
enforcerEngineVersion string
48+
instanceMutex sync.Mutex
4749
}
4850

4951
func NewNginxAppProtectInstanceWatcher(agentConfig *config.Config) *NginxAppProtectInstanceWatcher {
5052
return &NginxAppProtectInstanceWatcher{
5153
agentConfig: agentConfig,
5254
filesBeingWatched: make(map[string]bool),
55+
instanceMutex: sync.Mutex{},
5356
}
5457
}
5558

@@ -96,6 +99,9 @@ func (w *NginxAppProtectInstanceWatcher) Watch(ctx context.Context) {
9699
}
97100

98101
func (w *NginxAppProtectInstanceWatcher) NginxAppProtectInstance() *mpi.Instance {
102+
w.instanceMutex.Lock()
103+
defer w.instanceMutex.Unlock()
104+
99105
return w.nginxAppProtectInstance
100106
}
101107

@@ -210,6 +216,8 @@ func (w *NginxAppProtectInstanceWatcher) isNewInstance() bool {
210216
}
211217

212218
func (w *NginxAppProtectInstanceWatcher) createInstance(ctx context.Context) {
219+
w.instanceMutex.Lock()
220+
defer w.instanceMutex.Unlock()
213221
w.nginxAppProtectInstance = &mpi.Instance{
214222
InstanceMeta: &mpi.InstanceMeta{
215223
InstanceId: id.Generate(versionFilePath),

0 commit comments

Comments
 (0)