]> dgit.raspbian.org Git - git-annex.git/commitdiff
avoid throwing exception when the handle is closed
authorJoey Hess <joeyh@joeyh.name>
Wed, 18 Nov 2020 19:10:35 +0000 (15:10 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 18 Nov 2020 19:10:35 +0000 (15:10 -0400)
The handle could get closed eg, by cleanupProcess being called,
which forces the process to exit and closes all its handles.

At this point, the test case in https://git-annex.branchable.com/bugs/Buggy_external_special_remote_stalls_after_7245a9e/
is fixed.

Utility/Process.hs

index 958d239069e8ab3565c0f00cb245e3cbc60b356c..94321b2dfcc3abcded106ddc28878dc3bdeec9a2 100644 (file)
@@ -232,8 +232,8 @@ cleanupProcess (mb_stdin, mb_stdout, mb_stderr, pid) = do
 #endif
 
 {- | Like hGetLine, reads a line from the Handle. Returns Nothing if end of
- - file is reached, or if the process has exited and there is nothing more
- - buffered to read from the handle.
+ - file is reached, or the handle is closed, or if the process has exited
+ - and there is nothing more buffered to read from the handle.
  -
  - This is useful to protect against situations where the process might
  - have transferred the handle being read to another process, and so
@@ -284,9 +284,14 @@ hGetLineUntilExitOrEOF ph h = go []
        waitforinputorerror t = hWaitForInput h t
                `catchNonAsync` const (pure True)
 
-       getchar = catchIOErrorType EOF 
-               (const (pure Nothing)) 
-               (Just <$> hGetChar h)
+       getchar = 
+               catcherr EOF $
+                       -- If the handle is closed, reading from it is
+                       -- an IllegalOperation.
+                       catcherr IllegalOperation $
+                               Just <$> hGetChar h
+         where
+               catcherr t = catchIOErrorType t (const (pure Nothing))
 
        getloop buf cont =
                getchar >>= \case