[Haskell-cafe] createProcess interferes with sockets?

Roman Cheplyaka roma at ro-che.info
Mon Apr 22 12:21:18 CEST 2013


* Evan Laforge <qdunkan at gmail.com> [2013-04-22 12:41:33+0530]
> On Sun, Apr 21, 2013 at 9:25 PM, Donn Cave <donn at avvanta.com> wrote:
> > Quoth Evan Laforge <qdunkan at gmail.com>,
> >
> >> sleep = Process.createProcess (Process.proc "sleep" ["5"])
> >
> >  sleep = Process.createProcess
> >         ((Process.proc "sleep" ["5"]) {Process.close_fds = True})
> >
> >
> > - Because the client uses buffered I/O (hGetContents in this case, but
> > hGet-anything would be the same), it doesn't "see" the server response
> > until a) buffer full, or b) end of file (server closes connection.)
> >
> > - The server does close the connection, but after the "sleep" process
> > has forked off with a copy of the connection fd.  If it doesn't close
> > that fd explicitly, it holds it open until process exit (5 seconds.)
> 
> Oh I see, because the subprocess inherits the socket connection.  That
> makes sense, though it's tricky.  Tricky tricky unix.  Why does fork()
> have to be so complicated?

You probably want to set FD_CLOEXEC flag on your sockets.
This will cause execve to close them in the child process.

Roman



More information about the Haskell-Cafe mailing list