mirror of
https://github.com/status-im/consul.git
synced 2025-01-10 22:06:20 +00:00
state: do not delete from inside an iteration
Deleting from memdb inside an interation can cause a panic from Iterator.Next. This case is technically safe (for now) because the iterator is using the root radix tree not a modified one. However this could break at any time if someone adds an insert or delete to the coordinates table before this place in the function. It also sets a bad example, because generally deletes in an interator are not safe. So this commit uses the pattern we have in other places to move the deletes out of the iteration.
This commit is contained in:
parent
a4327305d1
commit
810424a61e
@ -740,7 +740,11 @@ func (s *Store) deleteNodeTxn(tx WriteTxn, idx uint64, nodeName string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed coordinate lookup: %s", err)
|
return fmt.Errorf("failed coordinate lookup: %s", err)
|
||||||
}
|
}
|
||||||
|
var coordsToDelete []interface{}
|
||||||
for coord := coords.Next(); coord != nil; coord = coords.Next() {
|
for coord := coords.Next(); coord != nil; coord = coords.Next() {
|
||||||
|
coordsToDelete = append(coordsToDelete, coord)
|
||||||
|
}
|
||||||
|
for _, coord := range coordsToDelete {
|
||||||
if err := tx.Delete("coordinates", coord); err != nil {
|
if err := tx.Delete("coordinates", coord); err != nil {
|
||||||
return fmt.Errorf("failed deleting coordinate: %s", err)
|
return fmt.Errorf("failed deleting coordinate: %s", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user