VOL-2332: Fix for same ONU being added twice in a race condition
Change-Id: I89ac6c92697735e1e4e4fd207d387fa608b17636
diff --git a/adaptercore/device_handler.go b/adaptercore/device_handler.go
index d17d997..e373523 100644
--- a/adaptercore/device_handler.go
+++ b/adaptercore/device_handler.go
@@ -865,11 +865,6 @@
log.Infow("new-discovery-indication", log.Fields{"sn": sn})
- if _, ok := dh.discOnus.Load(sn); ok {
- log.Warnw("onu-sn-is-already-being-processed", log.Fields{"sn": sn})
- return
- }
-
kwargs := make(map[string]interface{})
if sn != "" {
kwargs["serial_number"] = sn
@@ -878,7 +873,11 @@
return
}
- dh.discOnus.Store(sn, true)
+ if _, loaded := dh.discOnus.LoadOrStore(sn, true); loaded {
+ log.Warnw("onu-sn-is-already-being-processed", log.Fields{"sn": sn})
+ return
+ }
+
var onuID uint32
// check the ONU is already know to the OLT