-
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
ERROR: could not serialize access due to XXX (SQLSTATE 40001) #29
Comments
As a workaround for the moment, I've implemented a retry around the Acquire method: func internalAcquireWithContext(ctx context.Context) (*pglock.Lock, error) {
var lastSerializeError error
// Initialize counter
counter := 0
// Loop until the max retry is reached
for counter < 1000 {
// Acquire lock
ll, err := l.s.cl.AcquireContext(ctx, l.name)
// Check error
if err != nil {
// Check if it is a transaction serialize error
if strings.Contains(err.Error(), "could not serialize access due to") {
// Yes, so increment and retry
counter++
lastSerializeError = err
continue
}
// No, abort here
return nil, err
}
// Return lock
return ll, nil
}
// By default in this case, returning the transaction serialize error
return nil, lastSerializeError
} Tell me if I can help more than this. Oxyno-zeta |
hi @oxyno-zeta -- thanks for opening this issue. I couldn't repro this in my local environment. Do you have more information about the version of the PostgreSQL that you are using? |
Hello, yes I totally forgot this. I've edited the main post with this information. It is a 13.6. I can reproduce it on a 12.X. That's weird that you cannot reproduce it with this code. I reproduce it at every run... Maybe 2 parallel runs will trigger it ? Regards, Oxyno-zeta |
Two interesting aspects:
@oxyno-zeta -- could you please try reproducing the error with I have the impression that In any case, I commited 9190ade. Could you please try running |
Hello @ucirello , Thanks for checking this. I was afraid that this was coming from Gorm driver (pgx behind the scene) from your previous messages and your test confirms it. I will keep my workaround for the moment and try to see what isn't working with pgx in this specific case. I strongly think that your I will close this bug. Thanks for your work and your tests with me. If you need another test or debug from me, just tell me. Oxyno-zeta |
@oxyno-zeta -- I believe this version will fix your problems: https://github.com/cirello-io/pglock/releases/tag/v1.9.0 |
@ucirello : That's perfectly working ! Thanks for this commit and new release ! |
…rrors It is patched in upstream. See here: cirello-io/pglock#29
Hello @ucirello ,
I recently had those kind of errors:
This is failing on the begin transaction part but don't know why...
But I succeed by creating a repro-case.
Here is the code for the repro-case:
With this go mod main modules:
PG server is running on version 13.6.
Sometimes, it is long to appear, sometimes not.
This is relating to #26 I think.
Regards,
Oxyno-zeta
EDIT: Added the PG server version
The text was updated successfully, but these errors were encountered: