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

data race with cycle relation #7110

Open
zwell opened this issue Jul 17, 2024 · 1 comment
Open

data race with cycle relation #7110

zwell opened this issue Jul 17, 2024 · 1 comment
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@zwell
Copy link

zwell commented Jul 17, 2024

GORM Playground Link

go-gorm/playground#752

Description

In my project, hava some cycle orm relation, I use -race option to test, There is a certain probability that "DATA RACE"

Here are the test results for playgroud

==================
WARNING: DATA RACE
Read at 0x00c0005f2150 by goroutine 26:
  gorm.io/gorm/schema.(*Schema).guessRelation()
      E:/work/code/source/playground/gorm/schema/relationship.go:553 +0x1e44
  gorm.io/gorm/schema.(*Schema).parseRelation()
      E:/work/code/source/playground/gorm/schema/relationship.go:95 +0x744
  gorm.io/gorm/schema.ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/schema/schema.go:350 +0x4164
  gorm.io/gorm.(*Statement).ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/statement.go:493 +0x146
  gorm.io/gorm.(*Statement).Parse()
      E:/work/code/source/playground/gorm/statement.go:489 +0x3ab
  gorm.io/gorm.(*processor).Execute()
      E:/work/code/source/playground/gorm/callbacks.go:105 +0x386
  gorm.io/gorm.(*DB).First()
      E:/work/code/source/playground/gorm/finisher_api.go:129 +0x2f8
  gorm.io/playground.TestGORM.func2()
      E:/work/code/source/playground/main_test.go:23 +0xa4

Previous write at 0x00c0005f2150 by goroutine 25:
  gorm.io/gorm/schema.ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/schema/schema.go:365 +0x46b3
  gorm.io/gorm.(*Statement).ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/statement.go:493 +0x146
  gorm.io/gorm.(*Statement).Parse()
      E:/work/code/source/playground/gorm/statement.go:489 +0x3ab
  gorm.io/gorm.(*processor).Execute()
      E:/work/code/source/playground/gorm/callbacks.go:105 +0x386
  gorm.io/gorm.(*DB).First()
      E:/work/code/source/playground/gorm/finisher_api.go:129 +0x2f8
  gorm.io/playground.TestGORM.func1()
      E:/work/code/source/playground/main_test.go:16 +0xa4

Goroutine 26 (running) created at:
  gorm.io/playground.TestGORM()
      E:/work/code/source/playground/main_test.go:21 +0x4e
  testing.tRunner()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1742 +0x44

Goroutine 25 (running) created at:
  gorm.io/playground.TestGORM()
      E:/work/code/source/playground/main_test.go:14 +0x2c
  testing.tRunner()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1742 +0x44
==================
==================
WARNING: DATA RACE
Read at 0x00c0005f2168 by goroutine 26:
  gorm.io/gorm/schema.(*Schema).guessRelation()
      E:/work/code/source/playground/gorm/schema/relationship.go:553 +0x1e44
  gorm.io/gorm/schema.(*Schema).parseRelation()
      E:/work/code/source/playground/gorm/schema/relationship.go:95 +0x744
  gorm.io/gorm/schema.ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/schema/schema.go:350 +0x4164
  gorm.io/gorm.(*Statement).ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/statement.go:493 +0x146
  gorm.io/gorm.(*Statement).Parse()
      E:/work/code/source/playground/gorm/statement.go:489 +0x3ab
  gorm.io/gorm.(*processor).Execute()
      E:/work/code/source/playground/gorm/callbacks.go:105 +0x386
  gorm.io/gorm.(*DB).First()
      E:/work/code/source/playground/gorm/finisher_api.go:129 +0x2f8
  gorm.io/playground.TestGORM.func2()
      E:/work/code/source/playground/main_test.go:23 +0xa4

Previous write at 0x00c0005f2168 by goroutine 25:
  gorm.io/gorm/schema.ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/schema/schema.go:369 +0x489b
  gorm.io/gorm.(*Statement).ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/statement.go:493 +0x146
  gorm.io/gorm.(*Statement).Parse()
      E:/work/code/source/playground/gorm/statement.go:489 +0x3ab
  gorm.io/gorm.(*processor).Execute()
      E:/work/code/source/playground/gorm/callbacks.go:105 +0x386
  gorm.io/gorm.(*DB).First()
      E:/work/code/source/playground/gorm/finisher_api.go:129 +0x2f8
  gorm.io/playground.TestGORM.func1()
      E:/work/code/source/playground/main_test.go:16 +0xa4

Goroutine 26 (running) created at:
  gorm.io/playground.TestGORM()
      E:/work/code/source/playground/main_test.go:21 +0x4e
  testing.tRunner()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1742 +0x44

Goroutine 25 (running) created at:
  gorm.io/playground.TestGORM()
      E:/work/code/source/playground/main_test.go:14 +0x2c
  testing.tRunner()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1742 +0x44
==================
==================
WARNING: DATA RACE
Read at 0x00c0005f2180 by goroutine 26:
  gorm.io/gorm/schema.(*Schema).guessRelation()
      E:/work/code/source/playground/gorm/schema/relationship.go:553 +0x1e44
  gorm.io/gorm/schema.(*Schema).parseRelation()
      E:/work/code/source/playground/gorm/schema/relationship.go:95 +0x744
  gorm.io/gorm/schema.ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/schema/schema.go:350 +0x4164
  gorm.io/gorm.(*Statement).ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/statement.go:493 +0x146
  gorm.io/gorm.(*Statement).Parse()
      E:/work/code/source/playground/gorm/statement.go:489 +0x3ab
  gorm.io/gorm.(*processor).Execute()
      E:/work/code/source/playground/gorm/callbacks.go:105 +0x386
  gorm.io/gorm.(*DB).First()
      E:/work/code/source/playground/gorm/finisher_api.go:129 +0x2f8
  gorm.io/playground.TestGORM.func2()
      E:/work/code/source/playground/main_test.go:23 +0xa4

Previous write at 0x00c0005f2180 by goroutine 25:
  gorm.io/gorm/schema.ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/schema/schema.go:373 +0x4a7b
  gorm.io/gorm.(*Statement).ParseWithSpecialTableName()
      E:/work/code/source/playground/gorm/statement.go:493 +0x146
  gorm.io/gorm.(*Statement).Parse()
      E:/work/code/source/playground/gorm/statement.go:489 +0x3ab
  gorm.io/gorm.(*processor).Execute()
      E:/work/code/source/playground/gorm/callbacks.go:105 +0x386
  gorm.io/gorm.(*DB).First()
      E:/work/code/source/playground/gorm/finisher_api.go:129 +0x2f8
  gorm.io/playground.TestGORM.func1()
      E:/work/code/source/playground/main_test.go:16 +0xa4

Goroutine 26 (running) created at:
  gorm.io/playground.TestGORM()
      E:/work/code/source/playground/main_test.go:21 +0x4e
  testing.tRunner()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1742 +0x44

Goroutine 25 (running) created at:
  gorm.io/playground.TestGORM()
      E:/work/code/source/playground/main_test.go:14 +0x2c
  testing.tRunner()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      D:/Golang/sdk/go1.22.3/src/testing/testing.go:1742 +0x44
==================
@github-actions github-actions bot added the type:with reproduction steps with reproduction steps label Jul 17, 2024
@edwh
Copy link

edwh commented Oct 6, 2024

I see this problem too - usually in testing on CircleCI. Because it's a race, it's not 100% reproducible for me.

WARNING: DATA RACE
Write at 0x00c000706450 by goroutine 486:
  gorm.io/gorm/schema.(*Schema).guessRelation()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/schema/relationship.go:590 +0x121c
  gorm.io/gorm/schema.(*Schema).parseRelation()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/schema/relationship.go:93 +0x88b
  gorm.io/gorm/schema.ParseWithSpecialTableName()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/schema/schema.go:342 +0x3ac5
  gorm.io/gorm.(*Statement).ParseWithSpecialTableName()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/statement.go:493 +0x144
  gorm.io/gorm.(*Statement).Parse()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/statement.go:489 +0x3cd
  gorm.io/gorm.(*processor).Execute()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/callbacks.go:105 +0x3a8
  gorm.io/gorm.(*DB).First()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/finisher_api.go:129 +0x2e4
  github.com/freegle/iznik-server-go/message.GetMessagesByIds.func1.1()
      /home/circleci/project/message/message.go:120 +0x184

Previous read at 0x00c000706450 by goroutine 489:
  gorm.io/gorm/schema.ParseWithSpecialTableName()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/schema/schema.go:341 +0x3a08
  gorm.io/gorm.(*Statement).ParseWithSpecialTableName()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/statement.go:493 +0x144
  gorm.io/gorm.(*Statement).Parse()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/statement.go:489 +0xa6
  gorm.io/gorm.(*DB).ScanRows()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/finisher_api.go:577 +0x6d
  gorm.io/gorm.(*DB).Scan()
      /home/circleci/go/pkg/mod/gorm.io/[email protected]/finisher_api.go:535 +0x3da
  github.com/freegle/iznik-server-go/message.GetMessagesByIds.func1.4()
      /home/circleci/project/message/message.go:167 +0x1cf

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

No branches or pull requests

3 participants