Skip to content

Commit

Permalink
Test bug: Fix server connections not closing in TestEchoWithMessaging
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Stahl <[email protected]>
  • Loading branch information
darstahl committed Aug 4, 2017
1 parent c57b87d commit 3d52dc4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,18 @@ func MakeOpenFile(h syscall.Handle) (io.ReadWriteCloser, error) {

// closeHandle closes the resources associated with a Win32 handle
func (f *win32File) closeHandle() {
f.wgLock.Lock()
// Atomically set that we are closing, releasing the resources only once.
if !f.closing.swap(true) {
f.wgLock.Unlock()
// cancel all IO and wait for it to complete
cancelIoEx(f.handle, nil)
f.wgLock.Lock()
f.wg.Wait()
f.wgLock.Unlock()
// at this point, no new IO can start
syscall.Close(f.handle)
f.handle = 0
} else {
f.wgLock.Unlock()
}
}

Expand Down
4 changes: 3 additions & 1 deletion pipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ func TestEchoWithMessaging(t *testing.T) {
OutputBufferSize: 65536,
}
l, err := ListenPipe(testPipeName, &c)

if err != nil {
t.Fatal(err)
}
defer l.Close()

listenerDone := make(chan bool)
clientDone := make(chan bool)
go func() {
Expand All @@ -380,6 +380,8 @@ func TestEchoWithMessaging(t *testing.T) {
if e != nil {
t.Fatal(e)
}
defer conn.Close()

time.Sleep(500 * time.Millisecond) // make *sure* we don't begin to read before eof signal is sent
io.Copy(conn, conn)
conn.(CloseWriter).CloseWrite()
Expand Down

0 comments on commit 3d52dc4

Please sign in to comment.