Skip to content

`hIsReadable` and `hIsWritable` are incorrect for duplex handles

Inspecting the implementations of hIsReadable and hIsWritable in ghc-internal-9.1201.0, I found that these implementations are incorrect for duplex handles. Both use a shortcut for the DuplexHandle case: they just return True for duplex handles. This seems plausible at first sight, given that duplex handles always have a reading and a writing part and thus should be usable for reading and writing. However, this shortcut misses the check for whether the handle is closed or semi-closed, which is performed in the FileHandle case.

I propose to let hIsReadable and hIsWritable treat duplex handles similarly to file handles. Beware, however, that the solution is not to simply drop the special treatment of duplex handles, at least not for hIsWritable, because the withHandle_ operation, currently used for the FileHandle case, always operates on the reading part of a duplex handle.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information