diff -r a936d1368fc5 -r af8d8513d7de mercurial/windows.py --- a/mercurial/windows.py Fri Jul 06 17:57:46 2018 +0200 +++ b/mercurial/windows.py Mon Jul 09 09:50:23 2018 -0400 @@ -173,7 +173,7 @@ self.fp.write(s[start:end]) start = end except IOError as inst: - if inst.errno != 0: + if inst.errno != 0 and not win32.lasterrorwaspipeerror(inst): raise self.close() raise IOError(errno.EPIPE, 'Broken pipe') @@ -182,7 +182,7 @@ try: return self.fp.flush() except IOError as inst: - if inst.errno != errno.EINVAL: + if not win32.lasterrorwaspipeerror(inst): raise raise IOError(errno.EPIPE, 'Broken pipe')