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

Program exit exception, with fatal error: concurrent map writes #805

Open
leecoolyyds opened this issue Nov 20, 2024 · 0 comments
Open

Program exit exception, with fatal error: concurrent map writes #805

leecoolyyds opened this issue Nov 20, 2024 · 0 comments

Comments

@leecoolyyds
Copy link

We found that two tables, both associated with the same table and with the same name, 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"

Relation []*Relation `gorm:"foreignkey:Id;references:Id"`

}

type Info2 struct {
CreatedAt time.Time json:"created_at"
UpdatedAt time.Time json:"updated_at"

Relation []*Relation `gorm:"foreignkey:Id;references:Id"`

}

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!

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

No branches or pull requests

1 participant