Skip to content

chains: do not hold write subnetsLock in health checks #1460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ type manager struct {
unblockChainCreatorCh chan struct{}
chainCreatorShutdownCh chan struct{}

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

m.subnetsLock.Lock()
m.subnetsLock.RLock()
sb := m.subnets[chainParams.SubnetID]
m.subnetsLock.Unlock()
m.subnetsLock.RUnlock()

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

func (m *manager) subnetsNotBootstrapped() []ids.ID {
m.subnetsLock.Lock()
defer m.subnetsLock.Unlock()
m.subnetsLock.RLock()
defer m.subnetsLock.RUnlock()

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

m.subnetsLock.Lock()
sb := subnets.New(m.NodeID, sbConfig)
m.subnetsLock.Lock()
m.subnets[platformParams.SubnetID] = sb
sb.AddChain(platformParams.ID)
m.subnetsLock.Unlock()
Expand Down