DATA-DOG / go-txdb

Immutable transaction isolated sql driver for golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Deadlock found when trying to get lock

jehiah opened this issue · comments

For some number of months I've been encountering intermittent deadlock errors while using txdb in tests and I want to open an issue to see if anyone else has encountered this issue and might be able to shed light on this.

Error 1213: Deadlock found when trying to get lock; try restarting transaction

Unfortunately I don't have a reproducible test case, but it is a regular issue. Tests recently moved to run on a faster host and the rate of this issue increased.

Hi, it is coming from the database, not txdb sql driver. the reason why you get it, is most likely because you perform the SELECT ... FOR UPDATE and locking the same row in a single test scenario multiple times, or you do not close the db in each test.

Look into the example test each test should isolate itself within transaction, that is why tx-db is useful and it should close that db in the end of test (in background it just rollbacks transaction). If you create a global database connection and use it for number of tests (means you are using same transaction in many places), you will certainly run into similar issues. Each test case should isolate the context from other tests or global scope.

If you would show me your tests, I should be able to say what exact problem there is.