The race detector just found a race in my web app.
My code is really very straightforward. What I'm doing amounts to this:
package db
import "time"
type Foo struct {
Id string `db:"id"`
}
func InsertFoo() error {
return dbmap.Insert(&p)
}
// Call InsertFoo from a web handler.
==================
WARNING: DATA RACE
Read by goroutine 65:
x/vendor/github.com/go-gorp/gorp.(*TableMap).bindInsert()
/go/src/x/vendor/github.com/go-gorp/gorp/table_bindings.go:103 +0x8b
x/vendor/github.com/go-gorp/gorp.insert()
/go/src/x/vendor/github.com/go-gorp/gorp/gorp.go:505 +0x2f4
x/vendor/github.com/go-gorp/gorp.(*DbMap).Insert()
Previous write by goroutine 86:
x/vendor/github.com/go-gorp/gorp.(*TableMap).bindInsert()
/go/src/x/vendor/github.com/go-gorp/gorp/table_bindings.go:157 +0x942
x/vendor/github.com/go-gorp/gorp.insert()
/go/src/x/vendor/github.com/go-gorp/gorp/gorp.go:505 +0x2f4
x/vendor/github.com/go-gorp/gorp.(*DbMap).Insert()
/go/src/x/vendor/github.com/go-gorp/gorp/db.go:395 +0x99
I'm surprised that I could be the first person to report a race bug here.
The report suggests this line:
Is racing against this line:
Am I misusing Insert? I did not realise anywhere from the documentation that I would have to lock the DbMap during inserts.
The Insert docs don't mention anything about concurrency:
https://godoc.org/gopkg.in/gorp.v1#DbMap.Insert
And the DbMap docs suggest that I only have to make one per schema, not per request:
https://godoc.org/gopkg.in/gorp.v1#DbMap
Thoughts?
The race detector just found a race in my web app.
My code is really very straightforward. What I'm doing amounts to this:
I'm surprised that I could be the first person to report a race bug here.
The report suggests this line:
gorp/table_bindings.go
Line 103 in 75d359a
Is racing against this line:
gorp/table_bindings.go
Line 157 in 75d359a
Am I misusing
Insert? I did not realise anywhere from the documentation that I would have to lock theDbMapduring inserts.The
Insertdocs don't mention anything about concurrency:https://godoc.org/gopkg.in/gorp.v1#DbMap.Insert
And the
DbMapdocs suggest that I only have to make one per schema, not per request:https://godoc.org/gopkg.in/gorp.v1#DbMap
Thoughts?