Parcourir la source

fix(node-record): concurrent map read and write

Jacky il y a 1 jour
Parent
commit
c4b8b8f088
1 fichiers modifiés avec 2 ajouts et 2 suppressions
  1. 2 2
      internal/analytic/node_record.go

+ 2 - 2
internal/analytic/node_record.go

@@ -129,11 +129,11 @@ func RetrieveNodesStatus(ctx context.Context) {
 				default:
 					if err := nodeAnalyticRecord(e, ctx); err != nil {
 						logger.Error(err)
+						mutex.Lock()
 						if NodeMap[env.ID] != nil {
-							mutex.Lock()
 							NodeMap[env.ID].Status = false
-							mutex.Unlock()
 						}
+						mutex.Unlock()
 						select {
 						case <-retryTicker.C:
 						case <-ctx.Done():