Skip to content
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

Race when concurrently appending m2m association when preloaded model #5801

Closed
YeahItsMeAgain opened this issue Oct 22, 2022 · 1 comment
Closed
Assignees
Labels
help wanted Extra attention is needed type:with reproduction steps with reproduction steps

Comments

@YeahItsMeAgain
Copy link

GORM Playground Link

go-gorm/playground#534

Description

I tried appending to a m2m association inside a concurrent goroutines and for some reason it appended only some of the data.
While creating a minimal code example to test this i narrowed it down to this:

  • When the model is fetched from the db(previously created) & the associations are preloaded(Preload(clause.Associations)), it fails.
  • If any of this changes the test passes(note the comments in the code)
@a631807682
Copy link
Member

a631807682 commented Oct 25, 2022

https://github.com/go-gorm/playground/pull/534/files#diff-79ce3229c13921b79b1175dcb211336aaf84dfd8edcf19c07698934d4fe70e5eR47

This error seems to be a race caused by userCopy.Languages even though each userCopy is different.
I haven't found the bug, but this avoids it.

+ uuserCopy.Languages = nil
err := DB.Model(&userCopy).Association("Languages").Append(&languageCopy)

@a631807682 a631807682 added the help wanted Extra attention is needed label Oct 25, 2022
@jinzhu jinzhu closed this as completed Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

3 participants