Skip to content

Commit d4876ea

Browse files
author
waels
committed
[FAB-11640]: fix race condition in gossip/identity
Change-Id: I55294754a643f644aa5a15e1b8ce88117cc9f651 Signed-off-by: waels <wael.shama@ibm.com> "[FAB-11640]: fix and modify to RWMutex" Change-Id: I55294754a643f644aa5a15e1b8ce88117cc9f651 Signed-off-by: waels <wael.shama@ibm.com> [FAB-11640]: modify to use atomic operations Change-Id: I55294754a643f644aa5a15e1b8ce88117cc9f651 Signed-off-by: waels <wael.shama@ibm.com>
1 parent 2b9a816 commit d4876ea

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

gossip/identity/identity.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ func NewIdentityMapper(mcs api.MessageCryptoService, selfIdentity api.PeerIdenti
8787
}
8888

8989
func (is *identityMapperImpl) periodicalPurgeUnusedIdentities() {
90+
usageTh := GetIdentityUsageThreshold()
9091
for {
9192
select {
9293
case <-is.stopChan:
9394
return
94-
case <-time.After(usageThreshold / 10):
95+
case <-time.After(usageTh / 10):
9596
is.SuspectPeers(func(_ api.PeerIdentityType) bool {
9697
return false
9798
})
@@ -197,11 +198,12 @@ func (is *identityMapperImpl) SuspectPeers(isSuspected api.PeerSuspector) {
197198
// used for a long time
198199
func (is *identityMapperImpl) validateIdentities(isSuspected api.PeerSuspector) []*storedIdentity {
199200
now := time.Now()
201+
usageTh := GetIdentityUsageThreshold()
200202
is.RLock()
201203
defer is.RUnlock()
202204
var revokedIdentities []*storedIdentity
203205
for pkiID, storedIdentity := range is.pkiID2Cert {
204-
if pkiID != is.selfPKIID && storedIdentity.fetchLastAccessTime().Add(usageThreshold).Before(now) {
206+
if pkiID != is.selfPKIID && storedIdentity.fetchLastAccessTime().Add(usageTh).Before(now) {
205207
revokedIdentities = append(revokedIdentities, storedIdentity)
206208
continue
207209
}
@@ -275,12 +277,12 @@ func (si *storedIdentity) cancelExpirationTimer() {
275277
// Identities that are not used at least once during the given time
276278
// are purged
277279
func SetIdentityUsageThreshold(duration time.Duration) {
278-
usageThreshold = duration
280+
atomic.StoreInt64((*int64)(&usageThreshold), int64(duration))
279281
}
280282

281283
// GetIdentityUsageThreshold returns the usage threshold of identities.
282284
// Identities that are not used at least once during the usage threshold
283285
// duration are purged.
284286
func GetIdentityUsageThreshold() time.Duration {
285-
return usageThreshold
287+
return time.Duration(atomic.LoadInt64((*int64)(&usageThreshold)))
286288
}

0 commit comments

Comments
 (0)