Skip to content

Commit 850c6fd

Browse files
authored
chains: do not hold write subnetsLock in health checks (ava-labs#1460)
1 parent c125bc1 commit 850c6fd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

chains/manager.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ type manager struct {
241241
unblockChainCreatorCh chan struct{}
242242
chainCreatorShutdownCh chan struct{}
243243

244-
subnetsLock sync.Mutex
244+
subnetsLock sync.RWMutex
245245
// Key: Subnet's ID
246246
// Value: Subnet description
247247
subnets map[ids.ID]subnets.Subnet
@@ -322,9 +322,9 @@ func (m *manager) createChain(chainParams ChainParameters) {
322322
zap.Stringer("vmID", chainParams.VMID),
323323
)
324324

325-
m.subnetsLock.Lock()
325+
m.subnetsLock.RLock()
326326
sb := m.subnets[chainParams.SubnetID]
327-
m.subnetsLock.Unlock()
327+
m.subnetsLock.RUnlock()
328328

329329
// Note: buildChain builds all chain's relevant objects (notably engine and handler)
330330
// but does not start their operations. Starting of the handler (which could potentially
@@ -1285,8 +1285,8 @@ func (m *manager) IsBootstrapped(id ids.ID) bool {
12851285
}
12861286

12871287
func (m *manager) subnetsNotBootstrapped() []ids.ID {
1288-
m.subnetsLock.Lock()
1289-
defer m.subnetsLock.Unlock()
1288+
m.subnetsLock.RLock()
1289+
defer m.subnetsLock.RUnlock()
12901290

12911291
subnetsBootstrapping := make([]ids.ID, 0, len(m.subnets))
12921292
for subnetID, subnet := range m.subnets {
@@ -1323,8 +1323,8 @@ func (m *manager) StartChainCreator(platformParams ChainParameters) error {
13231323
return errNoPlatformSubnetConfig
13241324
}
13251325

1326-
m.subnetsLock.Lock()
13271326
sb := subnets.New(m.NodeID, sbConfig)
1327+
m.subnetsLock.Lock()
13281328
m.subnets[platformParams.SubnetID] = sb
13291329
sb.AddChain(platformParams.ID)
13301330
m.subnetsLock.Unlock()

0 commit comments

Comments
 (0)