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

fatal error: concurrent map writes in "parseRelation" function #7287

Open
leecoolyyds opened this issue Nov 21, 2024 · 4 comments
Open

fatal error: concurrent map writes in "parseRelation" function #7287

leecoolyyds opened this issue Nov 21, 2024 · 4 comments
Assignees
Labels

Comments

@leecoolyyds
Copy link

We found that two tables, both associated with the same table, were called at the same time when the program was started

err = db.Model(&bo.PeInfo{}).Order("id ASC").Find(&Info1List).Error

There's a probability the program will crash

I tested it on a virtual machine and kept rebooting the program for a minute. There is no problem when I list the association of a table or change the name of the association.

type Info1 struct {
CreatedAt time.Time json:"created_at"
UpdatedAt time.Time json:"updated_at"
Code string

Relation []*Relation gorm:"foreignkey:Code;references:Code"
}

type Info2 struct {
CreatedAt time.Time json:"created_at"
UpdatedAt time.Time json:"updated_at"
Code string
Relation []*Relation gorm:"foreignkey:Code;references:Code"
}

The following is the stack information when the program exits
fatal error: concurrent map writes
fatal error: concurrent map writes

goroutine 44 [running]:
gorm.io/gorm/schema.(*Schema).parseRelation(0xc000b190e0, 0xc000b252c0)
vendor/gorm.io/gorm/schema/relationship.go:100 +0x5d8
gorm.io/gorm/schema.ParseWithSpecialTableName({0x134e900, 0xc0009f25a0}, 0xc00073dc40, {0x1b0c068?, 0xc00013ed80?}, {0x0, 0x0})
vendor/gorm.io/gorm/schema/schema.go:341 +0x22c5
gorm.io/gorm.(*Statement).ParseWithSpecialTableName(0xc0009f6380, {0x134e900?, 0xc0009f25a0?}, {0x0?, 0x14f6e00?})
vendor/gorm.io/gorm/statement.go:492 +0x65
gorm.io/gorm.(*Statement).Parse(...)
vendor/gorm.io/gorm/statement.go:488
gorm.io/gorm.(*processor).Execute(0xc0007229b0, 0xc0007eca50?)
vendor/gorm.io/gorm/callbacks.go:105 +0x179
gorm.io/gorm.(*DB).Find(0xc000a10e38?, {0x1367600?, 0xc00093cb40}, {0x0, 0x0, 0x0})

Error code location, is indeed a map write
if relation.FieldSchema != relation.Schema && relation.Polymorphic == nil && field.OwnerSchema == nil {
relation.FieldSchema.Relationships.Relations[""+relation.Schema.Name+""+relation.Name] = relation
}

and my gorm version:
gorm.io/driver/mysql v1.5.2
gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde

Thank you very much!

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Nov 21, 2024
@leecoolyyds
Copy link
Author

It was the same when I upgraded to the latest version

Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@jinzhu
Copy link
Member

jinzhu commented Nov 21, 2024

Can you create a playground for this?

Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants