[GHC] #14730: Missing predicate for "ResourceVanished" IOException/IOErrorType

#14730: Missing predicate for "ResourceVanished" IOException/IOErrorType -------------------------------------+------------------------------------- Reporter: bit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 8.2.2 libraries/base | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- `IOErrorType` has a "`ResourceVanished`" constructor: https://hackage.haskell.org/package/base-4.10.1.0/docs/src/GHC.IO.Exception.... But there is no way to detect this for an `IOException` or `IOErrorType`. Here is some real-world code I found, where the author wants to catch "`ResourceVanished`", but resorts to catching all `IOException`: https://hackage.haskell.org/package/http-client-tls-0.3.5.1/docs/src /Network-HTTP-Client-TLS.html#convertConnection Docs for `hPutBuf` also mention the public existence of "`ResourceVanished`": https://hackage.haskell.org/package/base-4.10.1.0/docs/GHC-IO- Handle.html#v:hPutBuf Suggestion: We need to add functions: {{{#!haskell isResourceVanished :: IOError -> Bool resourceVanishedErrorType :: IOErrorType isResourceVanishedErrorType :: IOErrorType -> Bool }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14730 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14730: Missing predicate for "ResourceVanished" IOException/IOErrorType -------------------------------------+------------------------------------- Reporter: bit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by bgamari): Looks like there is indeed a gap here. Would you care to offer a patch? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14730#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14730: Missing predicate for "ResourceVanished" IOException/IOErrorType -------------------------------------+------------------------------------- Reporter: bit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vdukhovni): I am about to add some error handling to the "Network.Socket" library to deal with MacOS failing socket shutdown after EOF. MacOS returns EINVAL, which maps to 'InvalidArgument', which is similarly not available. And since some other systems, or a later MacOS may return ENOTCONN which would become 'ResourceVanished', I'd like to second the request to expose the full set of GHC Error types: {{{ -- GHC only: | UnsatisfiedConstraints | SystemError | ProtocolError | OtherError | InvalidArgument | InappropriateType | HardwareFault | UnsupportedOperation | TimeExpired | ResourceVanished | Interrupted }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14730#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14730: Missing predicate for "ResourceVanished" IOException/IOErrorType -------------------------------------+------------------------------------- Reporter: bit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by vdukhovni): * Attachment "Errno.hsc" added. Potential errno interface -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14730 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14730: Missing predicate for "ResourceVanished" IOException/IOErrorType -------------------------------------+------------------------------------- Reporter: bit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vdukhovni): In addition, it would be really cool if the "ioe_errno" value were accessible, at least as a number so it could be logged. While the associated C macro names are not all available on every platform, and any mapping to symbolic Haskell names would be unavoidably incomplete, a more ambitious interface might define any missing macros (that are common enough on most platforms to be supported) to 0 on platforms that lack that macro, and then a newtype + a set of PatternSynonyms would provide a usable Enum-like interface. As in the "Errno.hsc" example. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14730#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14730: Missing predicate for "ResourceVanished" IOException/IOErrorType -------------------------------------+------------------------------------- Reporter: bit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vdukhovni): Example Errno.hsc usages: {{{ $ ghci Errno.hs GHCi, version 8.6.3: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling System.IO.Errno ( Errno.hs, interpreted ) Ok, one module loaded. *System.IO.Errno> show EPERM "Operation not permitted" *System.IO.Errno> show $ IOErrno 0 "No error: 0" *System.IO.Errno> show $ IOErrno 1000 "Unknown error: 1000" *System.IO.Errno> strerror $ IOErrno 0 Just "No error: 0" *System.IO.Errno> strerror $ IOErrno 1000 Nothing *System.IO.Errno> fromEnum EPERM 1 *System.IO.Errno> toEnum 5 :: IOErrno Input/output error *System.IO.Errno> case toEnum 1 of { EPERM -> True; _ -> False } True }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14730#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14730: Missing predicate for "ResourceVanished" IOException/IOErrorType -------------------------------------+------------------------------------- Reporter: bit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by vdukhovni): * Attachment "Errno.hsc" added. Potential errno interface -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14730 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14730: Missing predicate for "ResourceVanished" IOException/IOErrorType -------------------------------------+------------------------------------- Reporter: bit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by vdukhovni): * Attachment "Errno.hsc" added. Potential 'IOErrno' interface, with curated errors from FreeBSD 12, Linux and MacOS -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14730 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14730: Missing predicate for "ResourceVanished" IOException/IOErrorType -------------------------------------+------------------------------------- Reporter: bit | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.2.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by vdukhovni): Also, perhaps the use of strerror(3) in "Foreign.C.Error" rather than strerror_r(3) is not entirely thread-safe under atypical conditions. If the kernel is newer than the C-library, it may return error numbers that lie outside the static string array used by strerror(3) and friends, and in that case, strerror(3) will use a static buffer to generate "Unknown error: <number>", but use of that buffer is not thread-safe. For this to be a problem, two threads have to encounter two different unknown to the C-library errors at essentially the same time. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14730#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC