Repository navigation
Description
This was discovered part of:
Somewhat similar to this, but different since in this case host has 16CPUs & no oci max parallelism:
What is the issue?
When running dagger call --source=.:default test all locally the CLI will remain stuck and it will need to be manually killed, as mentioned by @jpadams in a private thread. This happens approximately 1 in every 10 runs.
When a timeout is used - defaults to 30m in our case - this is what the system looks like for that entire period (I have this set to 60m in my local runs):

This was observed with the standard v0.11.4 Engine running in Docker:
/ # ps aux | grep '[e]ngine'
1 root 9:20 /usr/local/bin/dagger-engine --config /etc/dagger/engine.toml --debug
751327 root 4:07 /usr/local/bin/dagger-engine --config /etc/dagger/engine.toml --network-cidr=10.88.0.0/16 --network-name=dagger-dev
/ # cat /etc/dagger/engine.toml
debug = true
trace = false
insecure-entitlements = ["security.insecure"]Notice that there is:
- no
--oci-max-parallelismset - no GC custom config
When we hit this deadlocks, sending a SIGQUIT to the CLI returns the following: dagger-cli-v0.11.4-sigquit.txt. To visualise it, https://vito.github.io/swirly/ is most useful - thanks @vito 💪
Highlighting a couple of goroutines that caught my attention:



👆 there are a lot more channels here

👆 there are a lot more channels here
Tip
To visualize all the goroutines, load dagger-cli-v0.11.4-sigquit.txt into https://vito.github.io/swirly/
I was able to SIGQUIT the Engine when it deadlocked: dagger-engine-v0.11.4-sigquit.txt.gz
There were 4202 goroutines, which is a bit too much for https://vito.github.io/swirly/ to handle, but it did load part of it. These looked interesting:
👆 how many can sem.Acquire() at the same time?
👆 All GC workers were idle, which makes me believe that this is not GC related.
Do you see anything else out of place?
Questions
Does anything look suspicious to you @sipsma @vito @jedevc @aluzzardi ?
Anything else that we could add to make debugging easier?
Next steps
- Trigger this using our Engine & CLI tests,
SIGQUITthe Engine, upload the goroutines dump - Find a Dagger Cloud trace for when this happened in our own CI
- Have a simpler repro - our Engine & CLI tests are heavy & it takes a while to trigger this
- Thank you @aluzzardi 💪
- Trigger this using the repro,
SIGQUITthe Engine, upload that goroutines dump
FWIW, in the last 7 days, we have hit this issue 9% of the time across all our CI runs cc @samalba
Activity
jedevc commentedon May 15, 2024
Just linking to another client deadlock here: #7048. Might not be the same, but TL;DR - if the span doesn't ever complete, then the client will deadlock.
jedevc commentedon May 15, 2024
You don't happen to have a dagger cloud run or an engine SIGQUIT result do you? Without those, it's difficult to see what the engine is trying to do that's taking so long, or whether there's a runaway span somewhere.
Glancing through the stack trace, there's one specific one that stands out: goroutine 1 is stuck executing a query - it looks like everything else is just progress waiting for it terminate (there's also a goroutine leak for the streaming output, which should be fixed as part of #7272 when it gets removed entirely).
matipan commentedon May 15, 2024
Today I was running testdev on our CI and it looks like it got stuck (possibly a deadlock?) for about 40 minutes until finally exiting:
Checking the runner pod I could see the process was still up and the dagger engines (within the runner container) were up too:

Not sure if its useful but here are the logs of the engine in the node:
I don't have a link to dagger cloud, can one be dug up from the logs? The run was this one: https://github.com/dagger/dagger/actions/runs/9084221778/job/25002579112. Raw logs: https://pipelinesghubeus2.actions.githubusercontent.com/QzgPDIDyToE3J2EXFsF53FDrKXVmSNMaCDdKFJvQQISWafQ8Xj/_apis/pipelines/1/runs/126051/signedlogcontent/22?urlExpires=2024-05-15T17%3A48%3A16.9360768Z&urlSigningMethod=HMACV1&urlSignature=Unk2A%2F5EyznUgRLhgdfM39O0F8C1mzMXqHtg5vlf4Z4%3D
aluzzardi commentedon May 15, 2024
I'm able to make the engine misbehave by doing some stress testing:
code:
gerhard commentedon May 16, 2024
@jedevc Dagger Cloud trace + GitHub Actions job from last time this deadlock happened in our CI:
I am trying to reproduce locally so that I can get that goroutines dump from the Engine.
jedevc commentedon May 16, 2024
@aluzzardi I think that's definitely a legitimate failure, but I think this is likely different, that error message looks quite different from what we see in https://dagger.cloud/dagger/traces/3add32bb1a460bde62b9ccbbfd25d0ca?span=4e373cd85ec633b2&logs#4e373cd85ec633b2:L1542 (love the permalinking for logs in dagger cloud).
A couple notes on the linked trace:
Failed to connect; retrying... make request: returned error 500 Internal Server Error: client call for vkfcdrid1evyi1rddug25vrgg not foundis weird. I haven't seen this before.Debugging this isn't very fun as well. For the next release, I think we should make sure to get:
Service.Stopshould allow passing an arbitrary linux signal #7391Having both of these functionalities would probably help quite a bit in being able to hunt this down.
gerhard commentedon May 16, 2024
Starting with @aluzzardi's repro, I spawned 10k x
sleep 1in parallel. While the behaviour is completely different from what we have been hunting here, it's even worse:^Cthedaggerclientdaggerclient a good 5 minutes agoI didn't have patience to wait for the rest. This is what the above looks like in 1 picture:

This looks like a "thundering herd problem" to me. Without being able to look inside BuildKit, I cannot tell which component in stressed. My guess is that there is some sort of a worker pool that gets overwhelmed by the 10k containers that need to get spawned. Looking at the disk activity, my assumption is that there is a special goroutine that allocates an fs layer for each container which gets overwhelmed. Maybe @sipsma or @jedevc know more. I am going to see if I can attach some sort of continuous profiler and understand which function blocks the most. cc @thorfour @brancz
By the time I finished typing this up, things are back to normal:

sipsma commentedon May 16, 2024
My first guess (truly just a hunch though) at the error hit in @aluzzardi's example is that the system is running out of memory and processes are getting OOM killed. This is just based on the repro spinning up thousands of containers and the
137exit code. If that is what's happening, startingdmesg -win one terminal and then running the repro in another should show kernel logs about the OOM killer in the dmesg output.gerhard commentedon May 16, 2024
When I tried to reproduce @sipsma, I didn't get any OOM's, just a very slow start, and a slow progress. Most of it happened after
daggerCLI exited. Happy to pair-up sync in case that will help us make progress with this.sipsma commentedon May 17, 2024
@gerhard if you didn't see the same error as Andrea about exit code 137 then yeah it's probably not getting OOM killed (which is gonna vary host to host of course). That's just my guess about what happened for him.
I'm gonna start taking a look into this now. I yesterday independently hit an integ test case that hung for 5 minutes while waiting for OTEL to drain (and the 5 minute timeout was just the timeout of SDKs waiting for the
dagger sessionsubcommand to exit afterCloseis called, otherwise it would have hung forever afaict). Will make sure it still repros on main.No clue if it's related to everything else here though, will try to see if I can repro the other behavior here.
sipsma commentedon May 17, 2024
Okay yeah the 5 minute hang on OTEL draining repros consistently on main for me:
Funnily if you
SIGQUITor otherwise kill thedagger sessionsubprocess at any point once the hang starts but before the 5 minute timeout is hit the test still passes 😄 This is due to the fact that we aren't checking the error returned byClosein that test case (or almost any test cases for that matter, it's not something we really thought was needed to assert on previously).SIGQUIT on the
dagger sessionsubprocess of the Go SDK client used in the tests shows it stuck on these lines:Attached the engine container logs, w/
ExtraDebugenabled so it shows OTEL logs, for the full 5 minutes of waiting for the timeout: engine-hang.log2f421bb5aaf68593time="2024-05-17T02:02:09Z" level=debug msg="waiting for span" activeSpans=1 draining=true id=2f421bb5aaf68593 immediate=false span="HTTP GET" trace=f3101384332f0374dd87c5270c7453bdcc @vito
I think either way one output of all this should be to not block indefinitely for OTEL to drain (though having a generous timeout makes perfect sense).
Gonna try to repro the other hangs reported here. I guess it's possible they are related somehow, but the description of them so far does sound like something else entirely.
EDIT: of course after I post this and start reading I see this comment and issue #7387 (comment)
Will mention this over in that issue too.
sipsma commentedon May 17, 2024
@gerhard the SIGQUIT stack you attached in the description works in swirly for me, the logs seem to have one stack trace, then logs from the engine running again and then another SIGQUIT dump; if you trim it down to just the last goroutine dump it loads quickly. I created a gist you can put as the URL in swirly here: https://gist.githubusercontent.com/sipsma/bfd34d24b3a51c64fafa0eb93abbe5a1/raw/0b3640b1034ae509bdfec9791c985b011b2e85e7/gistfile1.txt
Looking at it, the most significant thing that sticks out is that there are actual containers still running that the engine has been waiting on for 53 minutes.

Which suggests that there are processes (possibly function calls) that are stuck and never exiting.
I am trying to repro locally now by just running the tests repeatedly, but if anyone else manages to repro it, execing into the engine container and running
ps auxor similar would be helpful to see what's there.sudo nsenter -m -p -t <the pid> ps auxps auxon the outer host would be sufficient too, just will need to sift through more processes.gerhard commentedon May 20, 2024
Thanks for helping out @sipsma!
I was able to trigger the hang again, and capture
pstree -won the Engine: test.all.race.failfast.parallel16.timeout180m.pstree-w.2024-05-18.20-31-24.txtHere is the full CLI log:
test.all.race.failfast.parallel16.timeout180m.2024-05-18.20-31-24.txt.gz
And this is just the Engine goroutines dump:
test.all.race.failfast.parallel16.timeout180m.sigquit.2024-05-18.20-31-24.txt.gz
This shows

3754goroutines:This is what they look like loaded in Swirly:
Screen.Recording.2024-05-20.at.13.32.46.mp4
There are a lot of grpc-related goroutines - is that normal? Anything else that looks odd?
I am going to try and use your repro to see if I can trigger this quicker. Before, it was taking up to 50mins. I now have a second host which is able to finish the same test suite in 30mins. Put together, I should be able to repro quicker.
This helps:
I am going to open a PR which makes those flags configurable.
vito commentedon May 20, 2024
Noticed one issue.
tl;dr telemetry draining is keyed on trace ID, so if you open multiple clients in one trace, closing the second client will hang waiting for the first client's session span, since it's in the same trace ID. (The timeout is 5 minutes.)
Context
I'm doing a bunch of refactoring now that the Go OTel SDK has logging (only HTTP, no gRPC - that'll come up later). Along the way I noticed
TestContainerLabelwas taking 10+ minutes - which is especially painful because this test isn'tt.Parallel(), so that 10 minutes is all spent watching this test awkwardly pass.Looking deeper, I noticed the test does something unusual.
First, it connects like normal:
dagger/core/integration/container_test.go
Line 1124 in da68978
But then in two of the sub-tests it uses
testutil.Query(for legacy reasons that can be fixed now):dagger/core/integration/container_test.go
Lines 1135 to 1144 in da68978
Internally,
testutil.Querycreates its own connection and callsClose()on it once it's done. Great! Except closing waits for telemetry to end, which will never end, because the other connection has a span hanging out.So there's a fundamental problem with the telemetry pub/sub; it shouldn't be keyed by
TraceID. Using the trace ID as the pub/sub topic was super convenient because that bit is always available1, but a trace ID is not actually 1:1 with the client.(Side issue: using the trace ID also meant there was cross-talk; a nested client would see all activity across the trace, instead of only its progress. Nothing breaks, but it's a bit weird.)
Solution?
Current idea is to just do away with the pub/sub and push telemetry straight to the client over gRPC, similar to how Buildkit attachables work - just gRPC services served on the cilent conn. Will look into this today. I mentioned earlier that there's no OTLP gRPC client for logging, but I can keep the one we wrote. It's easy to use for the engine (e.g. stdout/stderr log forwarding), we just can't package it for the Go SDK (long story - tl;dr it's a lot of code and our code sharing between the Go SDK and Go modules is limited to 1 package).
Footnotes
Using a span/log attribute or something instead would involve a custom processor or something to add it to everything. ↩
gerhard commentedon May 20, 2024
Thank you @vito for joining the party! That is definitely worth trying out, glad to help test the PR 💪
Just hit this which is related, but different:
dagger callcheck fails due to missing span & does not get fixed when re-running the job #7423@sipsma I am able to reliably reproduce:
./hack/dev go test -v -count=1 -timeout=1h -run=TestFileServiceSync/triggers_error ./core/integration/I can see the timeout, and this would explain why some tests take a much longer time than expected to return. I will spend more time debugging here:
dagger/sdk/go/internal/engineconn/session.go
Lines 165 to 167 in da68978
Anything else that you would like me to help reproduce / share?
jedevc commentedon May 20, 2024
@vito if we do away with the pubsub, does that break
dagger watch? No objections, just wanted to make sure I understand ❤️vito commentedon May 20, 2024
@jedevc Not necessarily; we could export to both the pub/sub and the per-client telemetry pretty easily.
gerhard commentedon May 21, 2024
@jedevc @vito can we move the conversation regarding telemetry draining to?
We can then keep this top-level and close it when running this command no longer hangs in e.g.
20consecutive runs.TomChv commentedon Jul 16, 2024
This should have been fixed with #7827
gerhard commentedon Aug 5, 2024
This has been resolved, regressed, and was eventually resolved for good:
One more related change coming up: