FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://code.google.com/p/go


Description:
net/smtp: remove data race from TestSendMail.

A data race was found in TestSendMail by the race detector.

Fixes issue 4559.

Please review this at https://codereview.appspot.com/6944057/

Affected files:
M src/pkg/net/smtp/smtp_test.go


Index: src/pkg/net/smtp/smtp_test.go
===================================================================
--- a/src/pkg/net/smtp/smtp_test.go
+++ b/src/pkg/net/smtp/smtp_test.go
@@ -11,6 +11,7 @@
"net"
"net/textproto"
"strings"
+ "sync"
"testing"
"time"
)
@@ -385,7 +386,8 @@
}
defer l.Close()

- go func(l net.Listener, data []string, w *bufio.Writer) {
+ var mu sync.Mutex
+ go func(l net.Listener, data []string, w *bufio.Writer, mu *sync.Mutex) {
i := 0
conn, err := l.Accept()
if err != nil {
@@ -394,6 +396,8 @@
}
defer conn.Close()

+ mu.Lock()
+ defer mu.Unlock()
tc := textproto.NewConn(conn)
for i < len(data) && data[i] != "" {
tc.PrintfLine(data[i])
@@ -401,6 +405,9 @@
i++
tc.PrintfLine(data[i])
}
+ if data[i] == "221 Goodbye" {
+ return
+ }
read := false
for !read || data[i] == "354 Go ahead" {
msg, err := tc.ReadLine()
@@ -416,7 +423,7 @@
}
i++
}
- }(l, strings.Split(server, "\r\n"), bcmdbuf)
+ }(l, strings.Split(server, "\r\n"), bcmdbuf, &mu)

err = SendMail(l.Addr().String(), nil, "test@example.com",
[]string{"other@example.com"}, []byte(strings.Replace(`From:
test@example.com
To: other@example.com
@@ -429,6 +436,8 @@
t.Errorf("%v", err)
}

+ mu.Lock()
+ defer mu.Unlock()
bcmdbuf.Flush()
actualcmds := cmdbuf.String()
if client != actualcmds {

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 17, '12 at 4:46a
activeDec 17, '12 at 7:06p
posts18
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase