mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
[simulator] Fix race condition when creating LocalBeaconNode (#2137)
## Issue Addressed We have a race condition when counting the number of beacon nodes. The user could end up seeing a duplicated service name (node_N). ## Proposed Changes I have updated to acquire write lock before counting the number of beacon nodes.
This commit is contained in:
@@ -101,14 +101,15 @@ impl<E: EthSpec> LocalNetwork<E> {
|
||||
beacon_config.network.enr_tcp_port = Some(BOOTNODE_PORT + count);
|
||||
}
|
||||
|
||||
let index = self.beacon_nodes.read().len();
|
||||
let mut write_lock = self_1.beacon_nodes.write();
|
||||
let index = write_lock.len();
|
||||
|
||||
let beacon_node = LocalBeaconNode::production(
|
||||
self.context.service_context(format!("node_{}", index)),
|
||||
beacon_config,
|
||||
)
|
||||
.await?;
|
||||
self_1.beacon_nodes.write().push(beacon_node);
|
||||
write_lock.push(beacon_node);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user