Fix race-condition when CreateHost is called at the same time that reloadHosts runs

This commit is contained in:
Brian Picciano 2024-12-12 21:26:09 +01:00
parent c21b3e0c33
commit d2c16573ff
2 changed files with 11 additions and 17 deletions

View File

@ -572,20 +572,9 @@ func (n *network) reloadHosts(ctx context.Context) error {
return fmt.Errorf("getting hosts from garage: %w", err) return fmt.Errorf("getting hosts from garage: %w", err)
} }
// TODO there's some potential race conditions here, where
// CreateHost could be called at this point, write the new host to
// garage and the bootstrap, but then this reload call removes the
// host from this bootstrap/children until the next reload.
newBootstrap := currBootstrap newBootstrap := currBootstrap
newBootstrap.Hosts = newHosts newBootstrap.Hosts = newHosts
// the daemon's view of this host's bootstrap info takes precedence over
// whatever is in garage. The garage version lacks the private credentials
// which must be stored locally.
thisHost := currBootstrap.ThisHost()
newBootstrap.Hosts[thisHost.Name] = thisHost
if _, err = n.reload(ctx, nil, &newBootstrap); err != nil { if _, err = n.reload(ctx, nil, &newBootstrap); err != nil {
return fmt.Errorf("reloading with new host data: %w", err) return fmt.Errorf("reloading with new host data: %w", err)
} }
@ -945,13 +934,8 @@ func (n *network) CreateHost(
return JoiningBootstrap{}, fmt.Errorf("putting new host in garage: %w", err) return JoiningBootstrap{}, fmt.Errorf("putting new host in garage: %w", err)
} }
// the new bootstrap will have been initialized with both all existing hosts
// (based on currBootstrap) and the host being created.
newBootstrap := currBootstrap
newBootstrap.Hosts = joiningBootstrap.Bootstrap.Hosts
n.logger.Info(ctx, "Reloading local state with new host") n.logger.Info(ctx, "Reloading local state with new host")
if _, err = n.reload(ctx, nil, &newBootstrap); err != nil { if err = n.reloadHosts(ctx); err != nil {
return JoiningBootstrap{}, fmt.Errorf("reloading child processes: %w", err) return JoiningBootstrap{}, fmt.Errorf("reloading child processes: %w", err)
} }

View File

@ -0,0 +1,10 @@
---
type: task
---
# IPv6 Support
It should be possible for nebula IP ranges to use designated private IPv6
ranges. Depending on how wide these ranges are it might even be possible for
CreateNetwork to automatically assign an IP range, with some hope that there's
little chance for collision.