Test bug: Fix server connections not closing in TestEchoWithMessaging

Signed-off-by: Darren Stahl <darst@microsoft.com>
This commit is contained in:
Darren Stahl
2017-08-04 10:24:26 -07:00
parent c57b87d6d4
commit 3d52dc4a97
2 changed files with 7 additions and 3 deletions
+4 -2
View File
@@ -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()
}
}