pipe: Resolve race between close and connect

This change resolves the issue where Accept() returns ERROR_NO_DATA
because the client closes the connection immediately. It resolves
the race by ignoring that particular connection and waiting on a
new one.
This commit is contained in:
John Starks
2018-01-09 13:28:13 -08:00
parent 78439966b3
commit ae842e48e0
2 changed files with 71 additions and 22 deletions
+29
View File
@@ -422,3 +422,32 @@ func TestEchoWithMessaging(t *testing.T) {
<-listenerDone
<-clientDone
}
func TestConnectRace(t *testing.T) {
l, err := ListenPipe(testPipeName, nil)
if err != nil {
t.Fatal(err)
}
defer l.Close()
go func() {
for {
s, err := l.Accept()
if err == ErrPipeListenerClosed {
return
}
if err != nil {
t.Fatal(err)
}
s.Close()
}
}()
for i := 0; i < 1000; i++ {
c, err := DialPipe(testPipeName, nil)
if err != nil {
t.Fatal(err)
}
c.Close()
}
}