Hi Pepijn,

Yeah, forking won't work well. I don't recommend that. One problem is that
if you fork() with an event loop running, both the parent and child
processes will end up with the same epoll FD and so will receive each
other's events, which will likely lead to chaos.

So I recommend spawning a subprocess and talking to it using RPC over a
unix socket. Yes, it adds some overhead, but really not that much.

-Kenton

On Thu, May 6, 2021 at 2:39 AM pepij...@gmail.com <pepijnde...@gmail.com>
wrote:

> Hey,
>
> I'm writing an API for some shared libraries that are written with a
> "binary" use in mind.
> They use a ton of global state and are not thread safe.
> Of course as a server, multiple users could try to use the server at the
> same time, these libraries can't deal with that. What's more they also like
> to segfault sometimes.
>
> So what I'd like to do is have these shared libraries completely in their
> own address space.
> What would be the best way to do that?
>
> One thing I thought could work is have a blocking accept loop, and then
> fork the handling of the connection. Not sure how this would work with kj.
>
> The other solution would be that you launch a process in the method
> handler that runs its own capnp server, and then proxy calls to it. Seems
> like it adds more overhead.
>
> Regards,
> Pepijn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cap'n Proto" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to capnproto+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/capnproto/99fcf2cf-e6e4-4918-8734-22b7f85cfb85n%40googlegroups.com
> <https://groups.google.com/d/msgid/capnproto/99fcf2cf-e6e4-4918-8734-22b7f85cfb85n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to capnproto+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/capnproto/CAJouXQmfWx6kk1Ejdr3bsfJQSxAw-aF%2BxA%2BBuAj4QRaj2pZ_uA%40mail.gmail.com.

Reply via email to