Accept connection in new process

10 views
Skip to first unread message

pepij...@gmail.com

unread,
May 6, 2021, 3:39:08 AMMay 6
to Cap'n Proto
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

Kenton Varda

unread,
May 6, 2021, 1:35:12 PMMay 6
to pepij...@gmail.com, 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.

-Kenton

--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/99fcf2cf-e6e4-4918-8734-22b7f85cfb85n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages