Repository navigation
Description
Started hitting a lot of flakes in the new TestLegacy suite, errors look like:
input: module.withSource.initialize resolve: failed to initialize module: failed to call module "test" to get functions: call constructor: process "go build -o /runtime ." did not complete successfully: exit code: 1
Stderr:
main.go:3:8: package dagger/test/internal/dagger is not in std (/usr/local/go/src/dagger/test/internal/dagger)
Could be unrelated, but it smells awfully similar to #7662 in that both could be explain by dirs missing files or otherwise having unexpected contents.
Thankfully can repro locally, so made some progress in debugging:
On one occurrence of the error in TestLegacyNoExec, the contents are showing that the go.mod of the module starts with:
module dagger/bare
go 1.22.4
This is extremely wrong.... That go.mod is the one that should be used for TestLegacyExportAbsolutePath.... This test should have module dagger/test (which explains the error)
The other files in there like main.go and dagger.gen.go all look like the right ones for TestLegacyNoExec. At least in this case it's just go.mod which is wrong.
Haven't root caused it yet, but could run from Go SDK problems all the way down to buildkit solver problems.
- All I can say is that the test case itself looks totally fine so far (and I can't imagine how this would ever be a test case problem anyways)
FTR, so far I've been debugging by running with this diff:
diff --git a/core/schema/sdk.go b/core/schema/sdk.go
index 8bbaed3e4..c031b15e1 100644
--- a/core/schema/sdk.go
+++ b/core/schema/sdk.go
@@ -364,9 +364,13 @@ func (sdk *goSDK) Runtime(
{
Name: "args",
Value: dagql.ArrayInput[dagql.String]{
+ "sh", "-c",
+ `go build -o /runtime . || (echo WTF && sleep 100000 && false)`,
+ /* TODO:
"go", "build",
"-o", goSDKRuntimePath,
".",
+ */
},
},
},Then running dagger -m dev call --source=.:default test custom --timeout=100h --run=TestLegacy --pkg=./core/integration --parallel=8 --count=100.
Wait for it to happen, find the sleep process pid with ps and do sudo nsenter -m -u -i -n -p -t <pid> sh to get inside the container.
Activity
sipsma commentedon Jul 12, 2024
Still working on root cause, just a few more significant things in meantime:
I looked at the overlay layers for the /src mount where the problematic go.mod file is, I can see that at the bottom layer it's the same situation: incorrect go.mod from the other test but correct main.go.
By itself, this is significant because it the bottom layer is the one created by the local import. So either:
dagger initbefore this call was wrong to begin withdagger callgot messed up and crossed wires with another one from the other test (which in turn could be due to a filesync bug or occurring during the copy-op we do for each local import)However even more interestingly, at least a few times I have seen the error getting hit on
dagger callstatements that have run after other dagger calls already ran successfully in the test. e.g. we've seen the error on this line specifically: https://github.com/sipsma/dagger/blob/05b530dbbbcc06519101ca2d471a5e05997f97f3/core/integration/legacy_test.go#L295-L295Since a previous
dagger callchained off the same previousdagger initsucceeded, either:dagger initis re-running incorrectly and also somehow outputting incorrect files (but only the second time)dagger call) is indeed the place where this is getting messed upAlso, some breadcrumbs on the place where that problematic value in go.mod gets set:
The significant thing here is that the
ModuleNamevalue used in go.mod is also used all over the place in codegen, so it's extremely difficult to imagine how this could be a codegen bug and probably lies somewhere else.Separately from all the above, at some point without changing anything I just suddenly stopped being able to repro 😢... Previously took a few attempts to hit, now I haven't in like an hour.
sipsma commentedon Jul 12, 2024
Picking back up today, thankfully was able to eventually repro again (though it took a long time).
Added this to the milestone because whatever is happening here seems deeply wrong, beyond just an annoying flake, and is worth getting to the bottom of ASAP.
sipsma commentedon Jul 12, 2024
Noticed that the behavior seems to generally be that once this get hit once, it's easy to hit again for a while. But it will go through long periods (literally hundreds of executions for me) of not getting hit.
I'm currently chasing down one hypothesis based on reading buildkit filesync code that:
/work) and have the same hostname (just the default one when no explicit hostname was set). This is due to the fact that those are our inputs to the "shared key hint" that buildkit filesync uses.go.modbetween the different clientsWorking on testing this now. If this is on the right track, the good news is that it's most likely an incredibly obscure condition for real-world users since it requires so many specific conditions and timing to align (different clients are using the same paths and have the same hostname, running the exact same ops at the same time, etc.).
sipsma commentedon Jul 12, 2024
Just confirmed that when the error happens, the
TestExecWithEntrypointclient that hit the error does indeed end up re-using a local sync cache ref from a client that originally ran inTestLegacyExportAbsolutePath.Like I said in previous comment, this isn't wrong in and of itself, so now need to track down if this is a differ problem or some race condition in the use of cache dir.
sipsma commentedon Jul 13, 2024
Somewhat hilariously, this bug appears to also be reliant on the fact that the two test cases have modules with names who are the same length (
BareandTest) 🫠This matters because the differ used by buildkit filesync only compares metadata. It appears that the two go.mods in these test cases are ending up with exactly equal file metadata (even though their contents aren't the same). That's why the length of the module name matters; if they weren't both 4 characters the go.mods would have different file sizes and thus be considered different.
The remaining mystery now is that ModTime is also considered by the differ and based on the logs I added to it, all of the go.mod files have exactly equal mod times down to the nanosecond. There's no way they are actually coinciding down to the nanosecond due to parallelism, so something else is going on still. Continuing to dig.
sipsma commentedon Jul 15, 2024
I'm working through adding logging to tons of places to track the mod time of go.mod as it flows back and forth between clients (export after dagger init, import on dagger call, etc.) to see what's happening here.
I did realize it might be worth double checking my assumption that there's no way the mod time of different files is corresponding down to the nanosecond. That felt like the probabilistic equivalent of hitting the lottery by my intuition, but I'm mildly less sure about that now.
This program will panic every few executions for me:
That, combined with the fact that it can take a very long time for me to hit the test flake sometimes (until the cache gets "poisoned" in my current hypothesis) makes the possibility of actually just getting different go.mod files with coincidentally equal nanosecond mod times feel somewhat less outrageous (but still crazy).
Still going to eliminate every other possibility first.
sipsma commentedon Jul 16, 2024
Okay, I think I've convinced myself that the mod times of these files are actually coincidentally ending up as the exact same nanosecond values. I wanted to be as sure as possible about this since I don't want to accidentally miss some other bug incorrectly setting the mtime of these files to be the same during filesync, etc.
There's a few crucial things that increase the likelihood of this happening:
go.modis not stored in these cache mounts, but we rungo mod tidyto fix it up, which involves downloading dependencies and updating other shared state. I can see fromstracethattidydoes all sorts offlocking on top of the cache mounts to synchronize this between concurrent processes.go mod tidycalls actually do end up synchronizing closely with each other and thus get to the point of "update go.mod file" at very close to the same timecurrent_timefunctioncurrent_timefunction is callingktime_get_coarse_real_ts64, which I found docs for that suggest it's a cached value (so plausible for different calls to get the same value) and possibly from up to 10ms in the past.This is all inherently very heisenberg-y so it's not feasible to get 100% confirmation, but between some wrapping with
straceand more dumb annotating various logs with the value of Go'stime.Now().UnixNano()that when the bug happens,go mod tidyis being called within 100s of microseconds of each other. Based on what I found above that's close enough to result in the mtimes of the files to get the same nanosecond values.So the end result is that:
/work), etc.In terms of the fix, I will probably just go with the approach where we generate a stable+unique identifier for each host that's stored in the user's XDG cache dir or something like that. We can then use that to ensure different clients don't accidentally re-use the filesync cache ref in situations like this.
sipsma commentedon Jul 23, 2024
fixed by #7943
chore(deps): update ⬆️ dagger to v0.12.3 (#294)
chore(deps): update dependency dagger/dagger to v0.12.3 (#5)
chore(deps): update ⬆️ dagger to v0.12.3 (#33)