Skip to content

Commit

Permalink
Avoid panic for double unlock
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Coffman <[email protected]>
  • Loading branch information
StevenACoffman committed Aug 8, 2024
1 parent 7792656 commit e0ad285
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pgxmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,12 @@ func findExpectationFunc[ET expectationType[t], t any](c *pgxmock, method string
if expected, ok = next.(ET); ok {
err = cmp(expected)
if err == nil {
// Note: next.Unlock not called yet, as we delay fulfill
break
}
}
// reset expected to nil if not matched, to avoid double mutex unlock panic below
expected = nil
if c.ordered {
if (!ok || err != nil) && !next.required() {
next.Unlock()
Expand All @@ -582,6 +585,7 @@ func findExpectationFunc[ET expectationType[t], t any](c *pgxmock, method string
}
return nil, fmt.Errorf(msg)
}
// only unlock to fulfill matching expectation
defer expected.Unlock()

expected.fulfill()
Expand Down

0 comments on commit e0ad285

Please sign in to comment.