mirror of
https://github.com/rwinkhart/go-winio.git
synced 2026-09-05 00:27:18 -04:00
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:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user