Skip to content

Commit d64bfdb

Browse files
committed
Disable logging in go routine
Logging was causing data race error. Here is one example of such error (from https://ci.appveyor.com/project/denisenkom/go-mssqldb/builds/36105319/job/qrymmer7mnvkbv2p): ``` 2020/11/03 03:32:09 initiating response reading 2020/11/03 03:32:09 got token tokenLoginAck 2020/11/03 03:32:09 got token tokenEnvChange 2020/11/03 03:32:09 got token tokenDone 2020/11/03 03:32:09 got DONE or DONEPROC status=0 2020/11/03 03:32:09 response finished 2020/11/03 03:32:09 SET XACT_ABORT ON; -- 16384 SET ANSI_NULLS ON; -- 32 SET ARITHIGNORE ON; -- 128 2020/11/03 03:32:09 initiating response reading 2020/11/03 03:32:09 got token tokenEnvChange 2020/11/03 03:32:09 got token tokenDone 2020/11/03 03:32:09 got DONE or DONEPROC status=1 2020/11/03 03:32:09 got token tokenDone 2020/11/03 03:32:09 got DONE or DONEPROC status=1 2020/11/03 03:32:09 got token tokenDone 2020/11/03 03:32:09 got DONE or DONEPROC status=0 2020/11/03 03:32:09 response finished 2020/11/03 03:32:09 select Options = @@options; 2020/11/03 03:32:09 initiating response reading 2020/11/03 03:32:09 got token tokenColMetadata 2020/11/03 03:32:09 got token tokenRow 2020/11/03 03:32:09 got token tokenDone 2020/11/03 03:32:09 got DONE or DONEPROC status=16 2020/11/03 03:32:09 (1 row(s) affected) 2020/11/03 03:32:09 response finished 2020/11/03 03:32:09 SET XACT_ABORT ON; -- 16384 SET ANSI_NULLS ON; -- 32 SET ARITHIGNORE ON; -- 128 2020/11/03 03:32:09 initiating response reading 2020/11/03 03:32:09 got token tokenEnvChange 2020/11/03 03:32:09 got token tokenDone 2020/11/03 03:32:09 got DONE or DONEPROC status=1 2020/11/03 03:32:09 got token tokenDone 2020/11/03 03:32:09 got DONE or DONEPROC status=1 2020/11/03 03:32:09 got token tokenDone 2020/11/03 03:32:09 got DONE or DONEPROC status=0 2020/11/03 03:32:09 response finished ================== WARNING: DATA RACE Read at 0x00c00033a043 by goroutine 55: testing.(*common).logDepth() c:/go113/src/testing/testing.go:665 +0xa8 testing.(*common).Log() c:/go113/src/testing/testing.go:658 +0x7e github.com/denisenkom/go-mssqldb.testLogger.Println() C:/gopath/src/github.com/denisenkom/go-mssqldb/tds_test.go:224 +0x5f github.com/denisenkom/go-mssqldb.optionalLogger.Println() C:/gopath/src/github.com/denisenkom/go-mssqldb/log.go:26 +0xa1 github.com/denisenkom/go-mssqldb.(*parseResp).dlog() C:/gopath/src/github.com/denisenkom/go-mssqldb/token.go:708 +0x176 github.com/denisenkom/go-mssqldb.(*parseResp).iter() C:/gopath/src/github.com/denisenkom/go-mssqldb/token.go:725 +0xcc6 github.com/denisenkom/go-mssqldb.processResponse() C:/gopath/src/github.com/denisenkom/go-mssqldb/token.go:813 +0x17c Previous write at 0x00c00033a043 by goroutine 40: testing.tRunner.func1() c:/go113/src/testing/testing.go:900 +0x35a testing.tRunner() c:/go113/src/testing/testing.go:913 +0x1c2 Goroutine 55 (running) created at: github.com/denisenkom/go-mssqldb.(*Stmt).processQueryResponse() C:/gopath/src/github.com/denisenkom/go-mssqldb/mssql.go:600 +0x1a5 github.com/denisenkom/go-mssqldb.(*Stmt).queryContext() C:/gopath/src/github.com/denisenkom/go-mssqldb/mssql.go:594 +0x1c2 github.com/denisenkom/go-mssqldb.(*Stmt).Query() C:/gopath/src/github.com/denisenkom/go-mssqldb/mssql.go:584 +0xbe github.com/denisenkom/go-mssqldb.TestQueryCancelLowLevel() C:/gopath/src/github.com/denisenkom/go-mssqldb/queries_test.go:1805 +0x54c testing.tRunner() c:/go113/src/testing/testing.go:909 +0x1a0 Goroutine 40 (running) created at: testing.(*T).Run() c:/go113/src/testing/testing.go:960 +0x658 testing.runTests.func1() c:/go113/src/testing/testing.go:1202 +0xad testing.tRunner() c:/go113/src/testing/testing.go:909 +0x1a0 testing.runTests() c:/go113/src/testing/testing.go:1200 +0x528 testing.(*M).Run() c:/go113/src/testing/testing.go:1117 +0x306 main.main() _testmain.go:362 +0x33e ================== 2020/11/03 03:32:18 [{Hello} {World} {TVP}] FAIL coverage: 78.2% of statements exit status 1 ``` Testing data race Testing data race Testing data race Testing data race Testing data race add comment
1 parent 2f2a555 commit d64bfdb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

token.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,14 +704,18 @@ func (ts *parseResp) sendAttention(ch chan tokenStruct) parseRespIter {
704704
}
705705

706706
func (ts *parseResp) dlog(msg string) {
707-
if ts.sess.logFlags&logDebug != 0 {
707+
// logging from goroutine is disabled to prevent
708+
// data race detection from firing
709+
// The race is probably happening when
710+
// test logger changes between tests.
711+
/*if ts.sess.logFlags&logDebug != 0 {
708712
ts.sess.log.Println(msg)
709-
}
713+
}*/
710714
}
711715
func (ts *parseResp) dlogf(f string, v ...interface{}) {
712-
if ts.sess.logFlags&logDebug != 0 {
716+
/*if ts.sess.logFlags&logDebug != 0 {
713717
ts.sess.log.Printf(f, v...)
714-
}
718+
}*/
715719
}
716720

717721
func (ts *parseResp) iter(ctx context.Context, ch chan tokenStruct, tokChan chan tokenStruct) parseRespIter {

0 commit comments

Comments
 (0)