Closed as not planned
Description
Issue description
When I use XORM, there is a data competition detection error.
The underlying database driver of XORM is this project.
Example code
sql := mysql.Sql().NewSession()
defer sql.Close()
if conditions, ok := reflect.ValueOf(entity).Elem().FieldByName(target).Interface().(define.SqlConditions); ok {
conditions.Where(func(query string, args ...any) {
sql = sql.Where(query, args...)
})
}
var result []map[string]any
if err := sql.Table(src).Find(&result); err != nil {
return nil, err
}
if target == "Hash" {
go func() {
for {
fmt.Println(result[0]["cache"])
}
}()
}
return result, nil
In the above code, go fun is the goroutine I use to test and open according to the basic understanding of sql.Table(src). Find(&result) This code should be returned after the query, not asynchronous, then multiple fmt.Println(result[0]["cache"]). The field will be changed (field type[]byte). The result after the change is about the residual data of the previous field, but there is no data error in the previous field.
Error log
Found 1 data race(s)
WARNING: DATA RACE
Write at 0x00c000440298 by main goroutine:
runtime.racewriterange()
:1 +0x14
internal/poll.ignoringEINTRIO()
/Users//SDK/go/go1.20/src/internal/poll/fd_unix.go:794 +0x2f0
internal/poll.(FD).Read()
/Users//SDK/go/go1.20/src/internal/poll/fd_unix.go:163 +0x20
net.(netFD).Read()
/Users//SDK/go/go1.20/src/net/fd_posix.go:55 +0x44
net.(conn).Read()
/Users//SDK/go/go1.20/src/net/net.go:183 +0x84
net.(TCPConn).Read()
:1 +0x4c
github.com/go-sql-driver/mysql.(buffer).fill()
/Users//go/pkg/mod/github.com/go-sql-driver/[email protected]/buffer.go:90 +0x328
github.com/go-sql-driver/mysql.(buffer).readNext()
/Users//go/pkg/mod/github.com/go-sql-driver/[email protected]/buffer.go:119 +0x54
github.com/go-sql-driver/mysql.(mysqlConn).readPacket()
/Users//go/pkg/mod/github.com/go-sql-driver/[email protected]/packets.go:32 +0xa4
github.com/go-sql-driver/mysql.(mysqlConn).readResultSetHeaderPacket()
/Users//go/pkg/mod/github.com/go-sql-driver/[email protected]/packets.go:537 +0x28
github.com/go-sql-driver/mysql.(mysqlStmt).query()
/Users//go/pkg/mod/github.com/go-sql-driver/[email protected]/statement.go:114 +0x23c
github.com/go-sql-driver/mysql.(mysqlStmt).QueryContext()
/Users//go/pkg/mod/github.com/go-sql-driver/[email protected]/connection.go:558 +0x1e0
database/sql.ctxDriverStmtQuery()
/Users//SDK/go/go1.20/src/database/sql/ctxutil.go:82 +0x9c
database/sql.rowsiFromStatement()
/Users//SDK/go/go1.20/src/database/sql/sql.go:2801 +0x140
database/sql.(DB).queryDC()
/Users//SDK/go/go1.20/src/database/sql/sql.go:1778 +0x378
database/sql.(DB).query()
/Users//SDK/go/go1.20/src/database/sql/sql.go:1726 +0xec
database/sql.(DB).QueryContext.func1()
/Users//SDK/go/go1.20/src/database/sql/sql.go:1704 +0x9c
database/sql.(DB).retry()
/Users//SDK/go/go1.20/src/database/sql/sql.go:1538 +0x4c
database/sql.(DB).QueryContext()
/Users//SDK/go/go1.20/src/database/sql/sql.go:1703 +0xc8
xorm.io/xorm/core.(DB).QueryContext()
/Users//go/pkg/mod/xorm.io/[email protected]/core/db.go:151 +0x224
xorm.io/xorm.(Session).queryRows()
/Users//go/pkg/mod/xorm.io/[email protected]/session_raw.go:52 +0x40c
xorm.io/xorm.(Session).noCacheFind()
/Users//go/pkg/mod/xorm.io/[email protected]/session_find.go:175 +0x180
xorm.io/xorm.(Session).find()
/Users//go/pkg/mod/xorm.io/[email protected]/session_find.go:161 +0xcec
xorm.io/xorm.(Session).Find()
/Users//go/pkg/mod/xorm.io/[email protected]/session_find.go:31 +0xa0
/data/model.(Mysql).Load.func1()
/Users//Server/Project//data/model/mysql.go:101 +0x374
/data/model.loadAndSet...
/Users//Server/Project//data/model/util.go:282 +0x334
/data/model.(Mysql).Load()
/Users//Server/Project//data/model/mysql.go:91 +0x88
main.(M).Load()
:1 +0x54
/define.Model.Load()
:1 +0x60
/data._RangeEntities()
/Users//Server/Project//data/data.go:49 +0x57c
/data.Load()
/Users//Server/Project//data/data.go:11 +0x38
main.main()
/Users//Server/Project/***/main.go:29 +0x170
Previous read at 0x00c00044029e by goroutine 30:
fmt.(pp).fmtBytes()
/Users//SDK/go/go1.20/src/fmt/print.go:528 +0x5f8
fmt.(pp).printArg()
/Users//SDK/go/go1.20/src/fmt/print.go:743 +0x480
fmt.(pp).doPrintln()
/Users//SDK/go/go1.20/src/fmt/print.go:1223 +0x40
fmt.Fprintln()
/Users//SDK/go/go1.20/src/fmt/print.go:304 +0x48
fmt.Println()
/Users//SDK/go/go1.20/src/fmt/print.go:314 +0x9c
/data/model.(Mysql).Load.func1.2()
/Users//Server/Project//data/model/mysql.go:107 +0x2c
Goroutine 30 (running) created at:
/data/model.(Mysql).Load.func1()
/Users//Server/Project//data/model/mysql.go:105 +0x3fc
/data/model.loadAndSet...
/Users//Server/Project//data/model/util.go:282 +0x334
/data/model.(Mysql).Load()
/Users//Server/Project//data/model/mysql.go:91 +0x88
main.(M).Load()
:1 +0x54
/define.Model.Load()
:1 +0x60
/data._RangeEntities()
/Users//Server/Project//data/data.go:49 +0x57c
/data.Load()
/Users//Server/Project//data/data.go:11 +0x38
main.main()
/Users//Server/Project/*/main.go:29 +0x170```
### Configuration
*Driver version (or git SHA):lastest
*Go version:1.20
*Server version:* MySQL 5.7.10
*Server OS:* OSX 13.2 (22D49)
Metadata
Metadata
Assignees
Labels
No labels