Skip to content

Commit

Permalink
[FAB-9149] fix data race in TestRegister_MutualTLS
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
sykesm committed Jul 2, 2018
1 parent 1e04fe8 commit 6dd7353
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions events/producer/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ func (ep *eventProcessor) cleanup() {
}

func (ep *eventProcessor) addSupportedEventTypes() {
gEventProcessor.addEventType(pb.EventType_BLOCK)
gEventProcessor.addEventType(pb.EventType_FILTEREDBLOCK)
ep.addEventType(pb.EventType_BLOCK)
ep.addEventType(pb.EventType_FILTEREDBLOCK)
}

// addEventType supported event
Expand Down
7 changes: 4 additions & 3 deletions events/producer/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,13 @@ func resetEventProcessor(useMutualTLS bool) {
}
return evt.TlsCertHash
}
gEventProcessor.BindingInspector = comm.NewBindingInspector(useMutualTLS, extract)

// reset the event consumers
gEventProcessor.Lock()
gEventProcessor.BindingInspector = comm.NewBindingInspector(useMutualTLS, extract)
gEventProcessor.eventConsumers = make(map[pb.EventType]*handlerList)
gEventProcessor.Unlock()

// re-register the event types
// re-register the event types (this acquires the ep lock)
gEventProcessor.addSupportedEventTypes()
}

Expand Down

0 comments on commit 6dd7353

Please sign in to comment.