Skip to content

Commit 6dd7353

Browse files
committed
[FAB-9149] fix data race in TestRegister_MutualTLS
The events/producer package uses a global variable to hold a reference to the singleton eventProcessor. Because of various anti-patterns around this singleton instance, the tests are forced to reset the object between tests. The reset that's performed between tests would race with the running go routines that were started when the event processor was created. The race is avoided by grabbing the mutex on the global event processor before resetting its state. While this does not address the anti-patterns, it's a focused change to fix the race. Change-Id: Ibd5be16a8f49cd9300e2288afbdc551b9a58b37c Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 1e04fe8 commit 6dd7353

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

events/producer/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ func (ep *eventProcessor) cleanup() {
168168
}
169169

170170
func (ep *eventProcessor) addSupportedEventTypes() {
171-
gEventProcessor.addEventType(pb.EventType_BLOCK)
172-
gEventProcessor.addEventType(pb.EventType_FILTEREDBLOCK)
171+
ep.addEventType(pb.EventType_BLOCK)
172+
ep.addEventType(pb.EventType_FILTEREDBLOCK)
173173
}
174174

175175
// addEventType supported event

events/producer/producer_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,13 @@ func resetEventProcessor(useMutualTLS bool) {
514514
}
515515
return evt.TlsCertHash
516516
}
517-
gEventProcessor.BindingInspector = comm.NewBindingInspector(useMutualTLS, extract)
518517

519-
// reset the event consumers
518+
gEventProcessor.Lock()
519+
gEventProcessor.BindingInspector = comm.NewBindingInspector(useMutualTLS, extract)
520520
gEventProcessor.eventConsumers = make(map[pb.EventType]*handlerList)
521+
gEventProcessor.Unlock()
521522

522-
// re-register the event types
523+
// re-register the event types (this acquires the ep lock)
523524
gEventProcessor.addSupportedEventTypes()
524525
}
525526

0 commit comments

Comments
 (0)