From 1ba55a6b1b8e90fd26a3baad496c47500e8147fa Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Wed, 19 Jul 2017 18:15:28 +0200 Subject: [PATCH] Don't increment the wait count if the file is closing This prevent a deadlock if `prepareIo()` is called on a closing file as `Done()` would never been called afterwards. Signed-off-by: Kenfe-Mickael Laventure --- file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file.go b/file.go index 613f31b5..9c9ee5d2 100644 --- a/file.go +++ b/file.go @@ -127,10 +127,10 @@ func (f *win32File) Close() error { // prepareIo prepares for a new IO operation. // The caller must call f.wg.Done() when the IO is finished, prior to Close() returning. func (f *win32File) prepareIo() (*ioOperation, error) { - f.wg.Add(1) if f.closing { return nil, ErrFileClosed } + f.wg.Add(1) c := &ioOperation{} c.ch = make(chan ioResult) return c, nil