Accept connection in new process

Skip to first unread message

May 6, 2021, 3:39:08 AMMay 6
to Cap'n Proto

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.


Kenton Varda

May 6, 2021, 1:35:12 PMMay 6
to, Cap'n Proto
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.


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
To view this discussion on the web visit
Reply all
Reply to author
0 new messages