-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix cocurrent upload package #21836
Fix cocurrent upload package #21836
Conversation
has, err := e.Exist(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if has { | ||
return key, ErrDuplicatePackage | ||
} | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's wrong. You might get has=false, err=nil
then return nil, nil
@@ -128,14 +128,21 @@ func TryInsertPackage(ctx context.Context, p *Package) (*Package, error) { | |||
LowerName: p.LowerName, | |||
} | |||
|
|||
has, err := e.Get(key) | |||
has, err := e.Exist(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong because Exist
does not populate the object with the content from the database.
And this doesn't fix the current problem because the error does not occur in these methods but when the transaction is committed. |
Although I haven't looked into the problem, I think using transaction correctly will resolve the concurrency problem. Database transactions will acquire |
When inserting failed, then check if the record does exist, if yes, then just return the record duplicated.