Skip to content

Commit

Permalink
Move Postdeploy call within InitUnit to before the unit DB insertio…
Browse files Browse the repository at this point in the history
…n. This avoids the case where interrupts or errors in postdeploy would leave a record of a unit in the database even though the actual container had been cleaned up.
  • Loading branch information
Szubie committed Jun 8, 2022
1 parent 2508479 commit a6f8b37
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions platform/host_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,11 @@ func (bh *BraveHost) InitUnit(backend Backend, unitParams *shared.Bravefile) (er
}
}

err = bh.Postdeploy(ctx, unitParams)
if err != nil {
return err
}

// Add unit into database

var braveUnit db.BraveUnit
Expand Down Expand Up @@ -985,13 +990,8 @@ func (bh *BraveHost) InitUnit(backend Backend, unitParams *shared.Bravefile) (er
braveUnit.Data = data

_, err = db.InsertUnitDB(database, braveUnit)
if err = shared.CollectErrors(err, ctx.Err()); err != nil {
return errors.New("failed to insert unit to database: " + err.Error())
}

err = bh.Postdeploy(ctx, unitParams)
if err != nil {
return err
return errors.New("failed to insert unit to database: " + err.Error())
}

return nil
Expand Down

0 comments on commit a6f8b37

Please sign in to comment.