@@ -143,6 +143,9 @@ func (w *NginxAppProtectInstanceWatcher) addWatcher(ctx context.Context, version
143143}
144144
145145func (w * NginxAppProtectInstanceWatcher ) readVersionFile (ctx context.Context , versionFile string ) {
146+ w .instanceMutex .Lock ()
147+ defer w .instanceMutex .Unlock ()
148+
146149 switch versionFile {
147150 case versionFilePath :
148151 w .version = w .readFile (ctx , versionFilePath )
@@ -167,6 +170,9 @@ func (w *NginxAppProtectInstanceWatcher) handleEvent(ctx context.Context, event
167170}
168171
169172func (w * NginxAppProtectInstanceWatcher ) handleFileUpdateEvent (ctx context.Context , event fsnotify.Event ) {
173+ w .instanceMutex .Lock ()
174+ defer w .instanceMutex .Unlock ()
175+
170176 switch event .Name {
171177 case versionFilePath :
172178 w .version = w .readFile (ctx , event .Name )
@@ -182,6 +188,9 @@ func (w *NginxAppProtectInstanceWatcher) handleFileUpdateEvent(ctx context.Conte
182188}
183189
184190func (w * NginxAppProtectInstanceWatcher ) handleFileDeleteEvent (event fsnotify.Event ) {
191+ w .instanceMutex .Lock ()
192+ defer w .instanceMutex .Unlock ()
193+
185194 switch event .Name {
186195 case versionFilePath :
187196 w .version = ""
@@ -212,6 +221,9 @@ func (w *NginxAppProtectInstanceWatcher) checkForUpdates(ctx context.Context) {
212221}
213222
214223func (w * NginxAppProtectInstanceWatcher ) isNewInstance () bool {
224+ w .instanceMutex .Lock ()
225+ defer w .instanceMutex .Unlock ()
226+
215227 return w .nginxAppProtectInstance == nil && w .version != ""
216228}
217229
@@ -245,13 +257,17 @@ func (w *NginxAppProtectInstanceWatcher) createInstance(ctx context.Context) {
245257}
246258
247259func (w * NginxAppProtectInstanceWatcher ) deleteInstance (ctx context.Context ) {
260+ w .instanceMutex .Lock ()
261+ defer w .instanceMutex .Unlock ()
262+
248263 slog .InfoContext (ctx , "NGINX App Protect instance not longer exists" )
249264 w .nginxAppProtectInstance = nil
250265}
251266
252267func (w * NginxAppProtectInstanceWatcher ) updateInstance (ctx context.Context ) {
253268 w .instanceMutex .Lock ()
254269 defer w .instanceMutex .Unlock ()
270+
255271 w .nginxAppProtectInstance .GetInstanceMeta ().Version = w .version
256272 runtimeInfo := w .nginxAppProtectInstance .GetInstanceRuntime ().GetNginxAppProtectRuntimeInfo ()
257273 if runtimeInfo == nil {
0 commit comments