Fix race error

#598
This commit is contained in:
Gert-Jan Timmer 2018-07-03 13:49:21 +02:00
parent 09cb77ebcc
commit c8d9a4a210
2 changed files with 8 additions and 0 deletions

View File

@ -33,6 +33,7 @@ import "C"
import (
"database/sql"
"database/sql/driver"
"sync"
)
var (
@ -45,6 +46,7 @@ func init() {
// SQLiteDriver implement sql.Driver.
type SQLiteDriver struct {
mu sync.Mutex
Config *Config
Extensions []string
ConnectHook func(*SQLiteConn) error
@ -52,6 +54,9 @@ type SQLiteDriver struct {
// Open database and return a new connection.
func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
d.mu.Lock()
defer d.mu.Unlock()
cfg, err := ParseDSN(dsn)
if err != nil {
return nil, err

View File

@ -22,6 +22,9 @@ var (
// The two-step sequence allows drivers to parse the name just once and also provides
// access to per-Conn contexts.
func (d *SQLiteDriver) OpenConnector(dsn string) (driver.Connector, error) {
d.mu.Lock()
defer d.mu.Unlock()
cfg, err := ParseDSN(dsn)
if err != nil {
return nil, err