Skip to content

Commit

Permalink
Ensuring locks are released when the server can't start
Browse files Browse the repository at this point in the history
  • Loading branch information
ItalyPaleAle committed Dec 7, 2020
1 parent 0b0b4f0 commit 65f1b91
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ You can use the optional "--address" and "--port" flags to control what address
// Request the info file
info, err = store.GetInfoFile()
if err != nil {
_ = store.ReleaseLock(context.Background())
return NewExecError(ErrorApp, "Error requesting the info file", err)
}
if info == nil {
_ = store.ReleaseLock(context.Background())
return NewExecError(ErrorUser, "Repository is not initialized", err)
}

Expand All @@ -118,6 +120,7 @@ You can use the optional "--address" and "--port" flags to control what address
// Derive the master key
masterKey, keyId, errMessage, err := GetMasterKey(info)
if err != nil {
_ = store.ReleaseLock(context.Background())
return NewExecError(ErrorUser, errMessage, err)
}
store.SetMasterKey(keyId, masterKey)
Expand Down Expand Up @@ -145,6 +148,9 @@ You can use the optional "--address" and "--port" flags to control what address
}
err = srv.Start(cmd.Context(), flagBindAddress, flagBindPort)
if err != nil {
if store != nil {
_ = store.ReleaseLock(context.Background())
}
return NewExecError(ErrorApp, "Could not start server", err)
}

Expand Down

0 comments on commit 65f1b91

Please sign in to comment.