mirror of
https://github.com/moby/buildkit.git
synced 2026-06-24 08:47:57 +00:00
There's a large potential for a lock contention issue in the gateway forwarder's logic. The previous iteration of this would keep a global mapping of the build ids and, when a forwarder for a build id didn't exist, the forwarder would wait 3 seconds for the build to register. The issue with lock contention comes after this. Instead of having a notification channel that a specific build was ready, the forwarder would wake up all goroutines that were waiting each time a build was registered. Since each of those builds took a read lock to check whether its build was present and registering subsequent builds took a write lock, it was very easy to end up in a lock contention scenario when starting many builds at the same time. Then it was easy to hit the 3 second timeout especially when the machine itself was under load. This changes the notification mechanism so the notify happens per build. Looking up a build id creates a forwarder registrar with a channel that can be polled for when the registration is complete. A forwarder will then only be notified and woken when that specific build id is ready by the go runtime rather than from the sync condition. Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>