The type of tricky case I'm thinking about is:
- Two different clients are connected to buildkit and both trying to forward a host socket at
/var/run/foo.sock. If we allow clients to choose their own stable ID, then let's say both clients choose to use the name foo.
- The two clients submit identical execs in parallel that depend on the socket. Buildkit will see the execs are identical and de-dupe their execution. It wouldn't matter that we still do all the setup w/ ClientIDs to route to the "correct" socket, there won't even be two separate requests to route correctly.
- In a lot of cases, that's totally fine. But it's also highly possible that the client expected their
/var/run/foo.sock to be talked to and would be surprised if it wasn't.
This is definitely not a common case, but it's not totally implausible either when dealing with shared engines running CI jobs in parallel.
Basically, what I'm suggesting is that we actually just leave that problem as is for the case when the socket is coming from a MainClientCaller. It's obscure enough that I wouldn't consider it a hair-on-fire problem. Allowing clients to choose their own stable ID and/or using the the client's hostname as a heuristic for that stable ID would improve the situation, and we should consider that, but not eliminate it.
Then, when it comes to sockets served by Functions, I think we can use a combination of the Function's digest and the path of the socket as the stable ID of the socket. That way, if the "thing behind the socket" changes, the Functions must change too, so the caching should work out like we want.
what if your function mounts two sockets, both from unstable paths.
This could still indeed be a problem if you don't have control over the path of the socket being setup, but one nice part of Functions being containerized is that it's easy to do stuff like create a stable symlink to an unstable path and then just use that instead. So I think I'd be okay with that sort of thing just needing to be documented. But also, I'd have no problem with additionally layering on support for optionally setting a stable name for the socket to deal with this too. That would be more convenient.