[Haskell-cafe] Bug in HTTP (bad internal error handling)
Bit Connor
bit at mutantlemon.com
Sat Oct 16 03:18:04 EDT 2010
Hello, I have reported this problem to the maintainer of the HTTP
package about 2 weeks ago, but have not yet received a response, so I
am reporting it here.
I am using a recent git check out of HTTP 4000.0.10
The bufferReadLine function from Network.TCP has a bug in how it
handles an IOException after it catches one. It checks for isEOFError
e, and that branch of code seems to be ok. The problem is how it
handles other types of IO errors. One type of such an error, for
example, is:
<socket: 117>: Data.ByteString.hGetLine: resource vanished (Connection
reset by peer)
After it catches this error, the function returns (line 376):
return (fail (show e))
The "fail" is running in the Either monad (The Result type = Either).
This calls the default Monad implementation of fail, which is just a
call to plain old error. This basically causes the entire program to
crash.
A simple fix, is to instead just reraise the original error:
ioError e
This will propagate the error through as a normal IOException, which
can then be caught by the caller (such as the caller of simpleHTTP).
By looking at the library code, the same bug seems to be in other
places (bufferGetBlock, bufferPutBlock), but I have only observed the
bug actually occurring in bufferReadLine.
Actually, it appears that simpleHTTP isn't actually supposed to throw
an IOException, and it is instead supposed to return a ConnError
result. So the real fix is to fix the code to make this happen. But
I've found simpleHTTP to throw an IOException in a lot of
circumstances, so for now I think the fix above is a good immediate
solution.
Thanks,
Bit Connor
More information about the Haskell-Cafe
mailing list