Error "no such job"
We’re experiencing build failures with the following message using the buildkitd:master tag:
error: failed to receive status: rpc error: code = Unknown desc = no such job rlh3vgwebkq3ik94bsfrbbml7
The error occurs almost immediately after running the below buildctl command:
buildctl --tlscacert /root/buildkit_ca.pem --tlscert /root/buildkit_cert.pem --tlskey /root/buildkit_key.pem
build
--progress=plain
--frontend=dockerfile.v0
--local context="."
--local dockerfile="frontend/"
--opt target="test"
--opt build-arg:GIT_BRANCH="$BUILDKITE_BRANCH"
--opt build-arg:FRONTEND_APP="platform"
--opt build-arg:GIT_COMMIT_SHA="$BUILDKITE_COMMIT"
--opt build-arg:GIT_COMMIT_MESSAGE="$BUILDKITE_MESSAGE"
--import-cache ref=snippedci/cache:test-snipped-frontend-platform-bobRBC-42-product-walkthrough-modal,type=registry
--import-cache ref=snippedci/cache:test-snipped-frontend-platform-master,type=registry
--export-cache ref=snippedci/cache:test-snipped-frontend-platform-bobRBC-42-product-walkthrough-modal,mode=max,type=registry
--output \"name=snippedci/snipped-snipped-platform:test-b65c81fa364a389491d208c573f08a38d07428d5,snippedci/snipped-frontend-platform:test-bobRBC-42-product-walkthrough-modal\",\"push=true\",\"type=image\"
The 'no such job' error repeats for all buildctl commands under the current CI run.
The infrastructure supporting buildkitd has a separate “builder node” running buildkitd with multiple worker nodes running buildctl commands. We are building multiple images in parallel within our CI pipeline.
The buildkitd server’s config:
[grpc]
address = ["tcp://0.0.0.0:1234"]
[grpc.tls]
ca = "/root/ca.pem"
cert = "/root/cert.pem"
key = "/root/key.pem"
[worker.oci]
enabled = true
gc = true
gckeepstorage = 9000000
[[worker.oci.gcpolicy]]
keepBytes = 450000000000
keepDuration = 21600
filters = ["type==source.local", "type==exec.cachemount", "type==source.git.checkout"]
[[worker.oci.gcpolicy]]
all = true
keepBytes = 450000000000
[worker.containerd]
enabled = false
gc = true
gckeepstorage = 9000000
[[worker.containerd.gcpolicy]]
keepBytes = 450000000000
keepDuration = 21600
filters = ["type==source.local", "type==exec.cachemount", "type==source.git.checkout"]
[[worker.containerd.gcpolicy]]
all = true
keepBytes = 450000000000
Some warnings I noticed in the buildkitd logs that may be relevant:
Apr 26 16:23:13 ip-10-4-32-6 buildkitd[16676]: time="2021-04-26T16:23:13Z" level=warning msg="failed to update distribution source for layer sha256:c7d6bca2b8dce72b5765be4c42f907cb
Apr 26 16:23:13 ip-10-4-32-6 buildkitd[16676]: time="2021-04-26T16:23:13Z" level=warning msg="failed to update distribution source for layer sha256:0241c68333ef9f824a96ccd9cee33848
Apr 26 16:23:13 ip-10-4-32-6 buildkitd[16676]: time="2021-04-26T16:23:13Z" level=warning msg="failed to update distribution source for layer sha256:5cc9d42688cba0452b1aca1b74120d39
Apr 26 16:23:13 ip-10-4-32-6 buildkitd[16676]: time="2021-04-26T16:23:13Z" level=warning msg="failed to update distribution source for layer sha256:f7ec5a41d630a33a2d1db59b95d89d93
Apr 26 16:23:13 ip-10-4-32-6 buildkitd[16676]: time="2021-04-26T16:23:13Z" level=warning msg="failed to update distribution source for layer sha256:b78b95af9b17013ded5fece8819e3cf5
Apr 26 16:23:13 ip-10-4-32-6 buildkitd[16676]: time="2021-04-26T16:23:13Z" level=warning msg="reference for unknown type: application/vnd.buildkit.cacheconfig.v0"
Apr 26 16:23:58 ip-10-4-32-6 buildkitd[16676]: time="2021-04-26T16:23:58Z" level=warning msg="reference for unknown type: application/vnd.buildkit.cacheconfig.v0"
Apr 26 16:24:14 ip-10-4-32-6 buildkitd[16676]: time="2021-04-26T16:24:14Z" level=warning msg="reference for unknown type: application/vnd.buildkit.cacheconfig.v0"
Apr 26 16:24:21 ip-10-4-32-6 buildkitd[16676]: time="2021-04-26T16:24:21Z" level=warning msg="reference for unknown type: application/vnd.buildkit.cacheconfig.v0"
The current workaround is to terminate/replace the buildkitd server. The new buildkitd server works great for a while, but eventually will start having the aforementioned error consistently. For more context, we are running parallel builds many times per day.
Thanks.
Are you using a round-robin proxy before buildkitd. The requests need to keep state in between them so if they end up in different nodes you would get an error like this.
@tonistiigi There is no proxy before buildkitd.
I have exactly same problem
[2021-06-23T12:22:58.624Z] error: failed to receive status: rpc error: code = Unknown desc = no such job ias13uqv1vfssyh35e6qiiev4
Buildkitd logs are the same:
...
│ time="2021-06-23T12:26:32Z" level=warning msg="failed to update distribution source for layer sha256:9e3d3596b1c85cd41a801fe090ddd1e813caafc6bc10d60f113ef651c6e2573f: content digest sha256:9e3d3596b1c85cd41a801fe090ddd1e813caafc6bc10d60f113ef651c6e257 │
│ time="2021-06-23T12:26:32Z" level=warning msg="failed to update distribution source for layer sha256:5a4454cc2c223eb586f9be10e84438571f7bc8acb828305d6f79421b814bbba3: content digest sha256:5a4454cc2c223eb586f9be10e84438571f7bc8acb828305d6f79421b814bbb │
│ time="2021-06-23T12:26:32Z" level=warning msg="failed to update distribution source for layer sha256:231b5cf7c3cda03414c3929eba263be877c6b28216ba7ef34700f8a71f39c131: content digest sha256:231b5cf7c3cda03414c3929eba263be877c6b28216ba7ef34700f8a71f39c1 │
│ time="2021-06-23T12:26:32Z" level=warning msg="failed to update distribution source for layer sha256:0656806a80db4143473751e3be35be41655c0698cc260983bf8257fe3385c1f2: content digest sha256:0656806a80db4143473751e3be35be41655c0698cc260983bf8257fe3385c1 │
│ time="2021-06-23T12:26:33Z" level=warning msg="reference for unknown type: application/vnd.buildkit.cacheconfig.v0" │
│ time="2021-06-23T12:27:16Z" level=warning msg="reference for unknown type: application/vnd.buildkit.cacheconfig.v0" │
│ time="2021-06-23T12:37:32Z" level=warning msg="reference for unknown type: application/vnd.buildkit.cacheconfig.v0" │
│ time="2021-06-23T12:37:39Z" level=warning msg="reference for unknown type: application/vnd.buildkit.cacheconfig.v0"
...
Restarting buildkitd helps. I use the latest master for buildkitd and docker buildx.
Hi! I spent some time reading the code base those past days and I think I’ve found what’s happening here. I've observed the error multiple times with this kind of timeline:
- Controller.Solve() and Controller.Status() are invoked more or less at the same time
- llbsolver.Status() is called almost instantaneously and returns "no such job" after the 3s timeout is reached
- llbsolver.Solve() is called more than 3s later and registers the job
Basically, because of a delay in the execution path of Controller.Solve() that is supposed to register a job, Status() ends with no such job.
—
The slow down comes from cacheExporterFunc() which is called in Controller.Solve(), if an exporter is configured, and just before llbsolver.Solve(). Within the cacheExporterFunc ot type "registry", a Docker resolver is configured with this HostsFunc callback that manages Docker authorizers. This function uses a mutex authHandlerNS.mu which is also used by another part of the code when refreshing tokens for a given registry.
As a result, when buildkitd is waiting on a token retrieval request, the race is on and other operations involving Status() might fail.
—
I wrote a reproducer. I hope I didn’t simplify the real code path too much https://gist.github.com/maxlaverse/9ac5f4e5b76c62cf6ccae9a2da897025
Right now we’re running a fork that has a dedicated mutex for r.handler.hosts, as it seems independent from the other protected variables.
@maxlaverse What calls that mutex before job is registered by solve call?https://github.com/moby/buildkit/blob/175e8415e38228dbb75e6b54efd2c8e9fc5b1cbf/cache/remotecache/registry/registry.go#L36-L57 only returns a callback without running the hosts handler.
Thanks for the quick feedback @tonistiigi!
The ResolveCacheExporterFunc returns a func(sm *session.Manager, hosts docker.RegistryHosts) we call in main when filling up the map containing all ResolveCacheExporterFunc by cache types:
https://github.com/moby/buildkit/blob/f726169f69d65f4f599ffd2d1a8342ace4236e2d/cmd/buildkitd/main.go#L659-L669
Therefore when we call cacheExporterFunc in Controller.Solve(), we're actually already calling this function ResolveCacheExporterFunc returns.
Within this function, there are two important steps that come into play: GetResolver() and remote.Pusher().
With the GetResolver() call, a docker.Resolver is instantiated with the HostsFunc() (that has the mutex) passed as an option:
https://github.com/moby/buildkit/blob/175e8415e38228dbb75e6b54efd2c8e9fc5b1cbf/util/resolver/pool.go#L75-L111
When afterwards we call remote.Pusher(), resolveDockerBase() is called, which calls base(), calling our callback hosts.
I had forgotten to remove a line in my Gist, just fixed it btw. Tests shouldn't fail if an unimplemented method is called.
By the way, I don't want to add confusion but I think we can connect some dots here.
I believe the issue https://github.com/moby/buildkit/issues/2367 is making this problem worse, and it's because both are combined that we have so much troubles:
- a job is being built, and is about to export an image cache to a registry
- dockerAuthorizer.Authorize() is called and locks the mutex we're talking about here
- there is a handler for that host, and therefore authhandler.authorize() is called
- then authHandler.doBearerAuth()
- authhandler.fetchToken()
- and finally sessionauth.FetchToken()
In the last one, sessionmanager.Any() is called to find an active session but there is none (that's the core of the https://github.com/moby/buildkit/issues/2367 issue). SinceAny() has a 5 seconds timeout when looking for a session, the mutex is held for 5 seconds, delaying a lot of llbsolver.Solve().
I don't have a trace with enough identifiers for me to be 100% confident about this theory, but I see the lock being held for 5 seconds when there is no active session, and therefore I think it's likely the explanation fits.