augustin-wien / augustina-backend

An open-source web shop designed for selling magazines on the street.
GNU Affero General Public License v3.0
7 stars 0 forks source link

fix: db deadlock on simultanious verifications #152

Closed nanu-c closed 10 months ago

nanu-c commented 10 months ago

Type of change

Description

IMPORTANT TO KNOW

With the recent changes in the error logs i was able to track down the origin of the deadlock into the queries to the GetVendor function, specifically to the call of UpdateAccountBalanceByOpenPayments <- which is a bad function because it mixes the usage of pgx.Tx and normal database transactions. In the verification we call GetVendor 2x so actually we were updating the balance 4 times in the verification process which lead to the deadlocks.

Builds on top of #151

Learnings:

CHANGES

GetVendor shouldn't always update the balance, because in the verification it's already taking care to do this.

TODO

Clean up the mixed usage of tgx.Tx and normal transactions in queries.go -> follow up pr.

Checklist: