Skip to content

Commit

Permalink
Merge pull request #1601 from stakwork/feat/mutex_lock_withdrawal
Browse files Browse the repository at this point in the history
Added mutex lock to budget withdrawal to prevent race conditions
  • Loading branch information
elraphty authored Mar 8, 2024
2 parents 940bea3 + 5c9a8d7 commit aeb39f9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions handlers/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ func (h *bountyHandler) MakeBountyPayment(w http.ResponseWriter, r *http.Request
}

func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Request) {
var m sync.Mutex
m.Lock()

ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)

Expand Down Expand Up @@ -599,6 +602,8 @@ func (h *bountyHandler) BountyBudgetWithdraw(w http.ResponseWriter, r *http.Requ
errMsg := formatPayError("Could not pay lightning invoice")
json.NewEncoder(w).Encode(errMsg)
}

m.Unlock()
}

func formatPayError(errorMsg string) db.InvoicePayError {
Expand Down

0 comments on commit aeb39f9

Please sign in to comment.