Skip to content

Commit 600466b

Browse files
committed
fix data race in tests by not starting a goroutine for each log line
Handlers can take some time to run, and it's expected that after Server.Wait() returns the handler has already finished executing. Also if a handler needs to process log lines concurrently it can start a goroutine itself. The following data race was triggered by tests: ================== WARNING: DATA RACE Read by goroutine 20: gopkg.in/mcuadros/go-syslog%2ev2.(*ServerSuite).TestTailFile() /Users/cezar.sa/go/src/gopkg.in/mcuadros/go-syslog.v2/server_test.go:43 +0x283 runtime.call16() /usr/local/Cellar/go/1.4.2/libexec/src/runtime/asm_amd64.s:401 +0x44 reflect.Value.Call() /usr/local/Cellar/go/1.4.2/libexec/src/reflect/value.go:296 +0xd8 launchpad.net/gocheck.func·006() /Users/cezar.sa/go/src/launchpad.net/gocheck/gocheck.go:733 +0x51d launchpad.net/gocheck.func·004() /Users/cezar.sa/go/src/launchpad.net/gocheck/gocheck.go:628 +0xf7 Previous write by goroutine 24: gopkg.in/mcuadros/go-syslog%2ev2.(*HandlerMock).Handle() /Users/cezar.sa/go/src/gopkg.in/mcuadros/go-syslog.v2/server_test.go:85 +0x36 Goroutine 20 (running) created at: launchpad.net/gocheck.(*suiteRunner).forkCall() /Users/cezar.sa/go/src/launchpad.net/gocheck/gocheck.go:629 +0x544 launchpad.net/gocheck.(*suiteRunner).forkTest() /Users/cezar.sa/go/src/launchpad.net/gocheck/gocheck.go:765 +0xf2 launchpad.net/gocheck.(*suiteRunner).runTest() /Users/cezar.sa/go/src/launchpad.net/gocheck/gocheck.go:770 +0x3f launchpad.net/gocheck.(*suiteRunner).run() /Users/cezar.sa/go/src/launchpad.net/gocheck/gocheck.go:584 +0x3aa launchpad.net/gocheck.Run() /Users/cezar.sa/go/src/launchpad.net/gocheck/run.go:76 +0x57 launchpad.net/gocheck.RunAll() /Users/cezar.sa/go/src/launchpad.net/gocheck/run.go:68 +0x132 launchpad.net/gocheck.TestingT() /Users/cezar.sa/go/src/launchpad.net/gocheck/run.go:56 +0x582 gopkg.in/mcuadros/go-syslog%2ev2.Test() /Users/cezar.sa/go/src/gopkg.in/mcuadros/go-syslog.v2/server_test.go:13 +0x35 testing.tRunner() /usr/local/Cellar/go/1.4.2/libexec/src/testing/testing.go:447 +0x133 Goroutine 24 (finished) created at: gopkg.in/mcuadros/go-syslog%2ev2.(*Server).parser() /Users/cezar.sa/go/src/gopkg.in/mcuadros/go-syslog.v2/server.go:196 +0x1bb gopkg.in/mcuadros/go-syslog%2ev2.(*Server).scan() /Users/cezar.sa/go/src/gopkg.in/mcuadros/go-syslog.v2/server.go:163 +0x146 ==================
1 parent 18aee50 commit 600466b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func (s *Server) parser(line []byte, client string) {
202202
logParts := parser.Dump()
203203
logParts["client"] = client
204204

205-
go s.handler.Handle(logParts, int64(len(line)), err)
205+
s.handler.Handle(logParts, int64(len(line)), err)
206206
}
207207

208208
//Returns the last error

0 commit comments

Comments
 (0)