fix: resolve RLock deadlock in Square mock client

Move m.mu.RUnlock to defer in GetCheckout and remove duplicate RLock/RUnlock around m.completed lookup. This prevents a deadlock when CheckoutPending error is returned but the RLock was already released.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-07-05 11:48:04 +01:00
co-authored by Sisyphus
parent 33c945159c
commit 296a67770e
+2 -5
View File
@@ -161,9 +161,9 @@ func (m *MockClient) GetCheckout(ctx context.Context, checkoutID string) (*Payme
log.Printf("[SQUARE-MOCK] GetCheckout: id=%s", checkoutID) log.Printf("[SQUARE-MOCK] GetCheckout: id=%s", checkoutID)
m.mu.RLock() m.mu.RLock()
checkout, ok := m.checkouts[checkoutID] defer m.mu.RUnlock()
m.mu.RUnlock()
checkout, ok := m.checkouts[checkoutID]
if !ok { if !ok {
return nil, fmt.Errorf("checkout not found: %s", checkoutID) return nil, fmt.Errorf("checkout not found: %s", checkoutID)
} }
@@ -172,10 +172,7 @@ func (m *MockClient) GetCheckout(ctx context.Context, checkoutID string) (*Payme
return nil, fmt.Errorf("checkout pending") return nil, fmt.Errorf("checkout pending")
} }
m.mu.RLock()
result, ok := m.completed[checkoutID] result, ok := m.completed[checkoutID]
m.mu.RUnlock()
if !ok { if !ok {
return nil, fmt.Errorf("checkout result not found: %s", checkoutID) return nil, fmt.Errorf("checkout result not found: %s", checkoutID)
} }