Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server/swap: avoid deadlock with maker redeem ack #2021

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions server/swap/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,15 @@ func (s *Swapper) processAck(msg *msgjson.Message, acker *messageAcker) {
// actor.
mktMatch := db.MatchID(acker.match.Match)

// If this is the maker's (optional) redeem ack sig, we can stop tracking
// the match. Do it here to avoid lock order violation (a deadlock trap).
if acker.isMaker && !acker.isAudit { // getting Sigs.MakerRedeem
log.Debugf("Deleting completed match %v", mktMatch)
s.matchMtx.Lock() // before locking matchTracker.mtx
s.deleteMatch(acker.match)
s.matchMtx.Unlock()
}

acker.match.mtx.Lock()
defer acker.match.mtx.Unlock()

Expand Down Expand Up @@ -1486,10 +1495,6 @@ func (s *Swapper) processAck(msg *msgjson.Message, acker *messageAcker) {
if acker.isMaker { // maker acknowledging the redeem req we sent regarding the taker redeem
acker.match.Sigs.MakerRedeem = ack.Sig
// We don't save that pointless sig anymore; use it as a flag.
log.Debugf("Deleting completed match %v", mktMatch)
s.matchMtx.Lock()
s.deleteMatch(acker.match)
s.matchMtx.Unlock()
} else { // taker acknowledging the redeem req we sent regarding the maker redeem
acker.match.Sigs.TakerRedeem = ack.Sig
if err = s.storage.SaveRedeemAckSigB(mktMatch, ack.Sig); err != nil {
Expand Down