fix missing from 5.04.3 ???

Simon Marlow
Fri, 14 Mar 2003 12:57:19 -0000

> Previous 5.04 releases had an exception handler missing from=20
> connectTo=20
> that results in a socket leaking if socketToHandle fails for=20
> some reason=20
> (I cant remember the exact circumstances at the moment, but=20
> it causes a=20
> server to die - I think the leak is caused when the client closes the=20
> connection during the handshake - ie somebody presses stop on a web=20
> browser because of a slow connection after the handshake has just=20
> started) - I suggested a fix along the lines of:
> connectTo hostname (Service serv) =3D do
>     proto <- getProtocolNumber "tcp"
>     port <- getServicePortNumber serv
>     he <- getHostByName hostname
>     sock <- socket AF_INET Stream proto
>     (do
>         connect sock (SockAddrInet port (hostAddress he))
>         socketToHandle sock ReadWriteMode)=20
> `Control.Exception.catch` (\e=20
> -> do sClose sock; throw e)

Sorry, that one didn't get merged into 5.04.x.  An oversight on my part.

You can work around the problem by using your own implementation of
connectTo, or copying the one from Network.hs in CVS.