Skip to content

Commit

Permalink
log/syslog: fix deadlock in test
Browse files Browse the repository at this point in the history
The problem was that server handlers block on done<-,
the goroutine that reads from done blocks on count<-,
and the main goroutine that is supposed to read from count
waits for server handlers to exit.
Fixes #5547.

R=golang-dev, dave, bradfitz
CC=golang-dev
https://golang.org/cl/9722043
  • Loading branch information
dvyukov committed May 24, 2013
1 parent 2ca589d commit 0806c97
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/pkg/log/syslog/syslog_test.go
Expand Up @@ -281,12 +281,12 @@ func TestConcurrentWrite(t *testing.T) {
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
err := w.Info("test")
if err != nil {
t.Errorf("Info() failed: %v", err)
return
}
wg.Done()
}()
}
wg.Wait()
Expand All @@ -296,8 +296,10 @@ func TestConcurrentReconnect(t *testing.T) {
crashy = true
defer func() { crashy = false }()

const N = 10
const M = 100
net := "unix"
done := make(chan string)
done := make(chan string, N*M)
addr, sock, srvWG := startServer(net, "", done)
defer os.Remove(addr)

Expand All @@ -310,29 +312,29 @@ func TestConcurrentReconnect(t *testing.T) {
// we are looking for 500 out of 1000 events
// here because lots of log messages are lost
// in buffers (kernel and/or bufio)
if ct > 500 {
if ct > N*M/2 {
break
}
}
count <- ct
}()

var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
wg.Add(N)
for i := 0; i < N; i++ {
go func() {
defer wg.Done()
w, err := Dial(net, addr, LOG_USER|LOG_ERR, "tag")
if err != nil {
t.Fatalf("syslog.Dial() failed: %v", err)
}
for i := 0; i < 100; i++ {
for i := 0; i < M; i++ {
err := w.Info("test")
if err != nil {
t.Errorf("Info() failed: %v", err)
return
}
}
wg.Done()
}()
}
wg.Wait()
Expand Down

0 comments on commit 0806c97

Please sign in to comment.