-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLSTATE 400001 error on multiple boxes trying to acquire the same named lock #26
Comments
Hi, @zaroman - thanks for the report, and sorry for taking long to respond. Do you have a synthetic repro case I could use to debug and fix the problem? Thanks! |
ping @zaroman ? |
Please reopen the issue with a repro-case |
Hello @ucirello , I recently had the same problem. Don't know what it the problem but I succeed by creating a repro-case. Here is the code for the repro-case: package main
import (
"fmt"
"strings"
"cirello.io/pglock"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
func main() {
// Connect to database
gormDb, err := gorm.Open(postgres.Open("host=localhost port=5432 user=postgres dbname=postgres password=postgres sslmode=disable"))
// Check if error exists
if err != nil {
panic(err)
}
// Initialize pg lock
// Get sql db
sqlDb, err := gormDb.DB()
// Check if error exists
if err != nil {
panic(err)
}
// Create pglock client
c, err := pglock.UnsafeNew(sqlDb)
// Check if error exists
if err != nil {
panic(err)
}
// Now create a lot of go routine with a lock acquire inside
for i := 0; i < 99; i++ {
go func() {
for {
lock, err := c.Acquire("lock-name")
if err != nil {
if strings.Contains(err.Error(), "could not serialize access due to") {
// Debug here
fmt.Println("here")
}
panic(err)
}
fmt.Println("got the lock !")
err = lock.Close()
if err != nil {
panic(err)
}
}
}()
}
<-make(chan bool, 1)
return
} With this go mod main modules:
Sometimes, it is long to appear, sometimes not. This is failing on the begin transaction part but still don't know why... Regards, Oxyno-zeta |
@oxyno-zeta -- could you please open a new issue with the repro case? Thanks. |
@ucirello Sure. No problem. |
We are trying to use this library to implements distributed locking across multiple instances of an application. When 2 or more of these instances try to acquire a lock with the same name, we are sometimes seeing the following error:
We are using postgres 11.11 and pgx.
When acquiring the lock, we use:
The client is being initialized as follows:
We have other locks with different names that could be acquired on other threads on the same machines.
The text was updated successfully, but these errors were encountered: