Fix panic when starting up daemon with existing bootstrap
This commit is contained in:
parent
1ea16d80e4
commit
af69f1cfba
@ -223,13 +223,10 @@ func NewDaemon(
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// initialize must be called with d.l write lock held, but it will unlock the
|
||||
// lock itself.
|
||||
// initialize must be called with d.l write lock held.
|
||||
func (d *daemon) initialize(
|
||||
ctx context.Context, currBootstrap bootstrap.Bootstrap,
|
||||
) error {
|
||||
defer d.l.Unlock()
|
||||
|
||||
// we update this Host's data using whatever configuration has been provided
|
||||
// by the daemon config. This way the daemon has the most up-to-date
|
||||
// possible bootstrap. This updated bootstrap will later get updated in
|
||||
@ -493,22 +490,20 @@ func (d *daemon) CreateNetwork(
|
||||
}
|
||||
|
||||
d.l.Lock()
|
||||
defer d.l.Unlock()
|
||||
|
||||
if d.state != daemonStateNoNetwork {
|
||||
d.l.Unlock()
|
||||
return ErrAlreadyJoined
|
||||
}
|
||||
|
||||
if len(d.daemonConfig.Storage.Allocations) < 3 {
|
||||
d.l.Unlock()
|
||||
return ErrInvalidConfig.WithData(
|
||||
"At least three storage allocations are required.",
|
||||
)
|
||||
}
|
||||
|
||||
// initialize will unlock d.l
|
||||
err = d.initialize(ctx, hostBootstrap)
|
||||
if err != nil {
|
||||
if err = d.initialize(ctx, hostBootstrap); err != nil {
|
||||
return fmt.Errorf("initializing daemon: %w", err)
|
||||
}
|
||||
|
||||
@ -519,21 +514,19 @@ func (d *daemon) JoinNetwork(
|
||||
ctx context.Context, newBootstrap JoiningBootstrap,
|
||||
) error {
|
||||
d.l.Lock()
|
||||
defer d.l.Unlock()
|
||||
|
||||
if d.state != daemonStateNoNetwork {
|
||||
d.l.Unlock()
|
||||
return ErrAlreadyJoined
|
||||
}
|
||||
|
||||
err := secrets.Import(ctx, d.secretsStore, newBootstrap.Secrets)
|
||||
if err != nil {
|
||||
d.l.Unlock()
|
||||
return fmt.Errorf("importing secrets: %w", err)
|
||||
}
|
||||
|
||||
// initialize will unlock d.l
|
||||
err = d.initialize(ctx, newBootstrap.Bootstrap)
|
||||
if err != nil {
|
||||
if err = d.initialize(ctx, newBootstrap.Bootstrap); err != nil {
|
||||
return fmt.Errorf("initializing daemon: %w", err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user