Code RoomRetry holds transaction lock
HardPrep Room Coding #2134

Retry holds transaction lock

Code reviewDatabases & SQLConcurrencySenior–Staff~20 min

Review this Go code that retries a flaky downstream call from inside an open DB transaction.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1tx, _ := db.Begin()
2if _, err := tx.Exec("UPDATE accounts SET balance = balance - $1 WHERE id=$2", amt, id); err != nil {
3 tx.Rollback(); return err
4}
5var resp Resp
6for i := 0; i < 5; i++ {
7 resp, err = ledger.Post(ctx, id, amt) // external HTTP, ~1s timeout each
8 if err == nil { break }
9 time.Sleep(time.Second)
10}
11tx.Commit()
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.