Skip to content

Commit 65f1b91

Browse files
authored
Ensuring locks are released when the server can't start
1 parent 0b0b4f0 commit 65f1b91

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cmd/serve.go

+6
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ You can use the optional "--address" and "--port" flags to control what address
107107
// Request the info file
108108
info, err = store.GetInfoFile()
109109
if err != nil {
110+
_ = store.ReleaseLock(context.Background())
110111
return NewExecError(ErrorApp, "Error requesting the info file", err)
111112
}
112113
if info == nil {
114+
_ = store.ReleaseLock(context.Background())
113115
return NewExecError(ErrorUser, "Repository is not initialized", err)
114116
}
115117

@@ -118,6 +120,7 @@ You can use the optional "--address" and "--port" flags to control what address
118120
// Derive the master key
119121
masterKey, keyId, errMessage, err := GetMasterKey(info)
120122
if err != nil {
123+
_ = store.ReleaseLock(context.Background())
121124
return NewExecError(ErrorUser, errMessage, err)
122125
}
123126
store.SetMasterKey(keyId, masterKey)
@@ -145,6 +148,9 @@ You can use the optional "--address" and "--port" flags to control what address
145148
}
146149
err = srv.Start(cmd.Context(), flagBindAddress, flagBindPort)
147150
if err != nil {
151+
if store != nil {
152+
_ = store.ReleaseLock(context.Background())
153+
}
148154
return NewExecError(ErrorApp, "Could not start server", err)
149155
}
150156

0 commit comments

Comments
 (0)