[Spread-users] Spread and fork ()

J C Lawrence claw at kanga.nu
Tue Nov 23 17:17:32 EST 2004


On Tue, 23 Nov 2004 12:05:36 -0500
John Schultz <jschultz at spreadconcepts.com> wrote:

> Currently, Spread doesn't really support the fork() process model.

Oh dear.

In python terms (my application is written in Python), I've been
assuming that I can safely do:

  spread_handle.disconnect ()
  pid = os.fork ()
  if pid != 0: # Parent
    spread_handle = spread.connect (...)
    spread_handle.join (...)
    ...etc
  else: # Child
    spread_handle = spread.connect (...)
    spread_handle.join (...)
    ...etc

Is this unsafe?

> But, SP_close() also sends a signal back to the Spread daemon, which
> causes it to close the connection on its end, which isn't what you
> usually want in a fork/close model.  There is an unexposed function in
> the library called SP_kill that simply closes the fd and cleans up the
> internal connection state, but its use is not "officially" supported.

Yeah, this is what raised alarm bells with me regarding fork().  It
didn't make sense that I could fork() an open spread connection safely
given spread's logical model.

> Finally, Spread uses pthread mutexes to synchronize use of its
> internal connection state(s).  But, Spread does not install fork
> handlers using pthread_atfork() to reset all the mutexes properly.
> So, in a forked child mutexes may be held by non-existent threads in
> the new process.

Is there a potential for that to still be true in the above disconnected
case?

--
J C Lawrence
---------(*)                Satan, oscillate my metallic sonatas.
claw at kanga.nu               He lived as a devil, eh?
http://www.kanga.nu/~claw/  Evil is a name of a foeman, as I live.




More information about the Spread-users mailing list