Reputation: 165
I have two processes A and B that use gRPC protocol over Unix domain sockets for remote procedural call. I want to replace process B with updated version of B' seamlessly. One of the requirement to do this is transfer the unix domain socket for gRPC from B to B'. I know some proxies like Envoy and HAproxy transfer network sockets seamlessly without losing connections. Can we do the same thing with Unix domain sockets?
Upvotes: 1
Views: 757
Reputation: 69346
Yes, this is technically possible. In Linux you can transfer any file descriptor (including one referring to a open Unix domain socket) from one process to another by using a Unix domain socket (see man 7 unix
under "Ancillary messages"). So yeah, I would say that what you ask for is perfectly doable.
The real question is how you plan on doing it, as it could get complicated depending on your specific scenario. It's simple enough to do in a low-level language like C:
sendmsg
with an appropriately built msghdr
structure. In this case you would send the fd of your other Unix socket that you wish to "transfer".recvmsg
.See Sending file descriptor by Linux socket for a working example in C.
As per other programming languages, I suppose you will have to get your hands dirty digging through the documentation to find out the corresponding functions or syscall wrappers used to do the above.
Upvotes: 2