-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: linker repeatedly invoked for cached test results #49267
Comments
@bcmills brought this issue to my attention in CL 376134 and I had a chance to investigate a bit. I still have questions but I think I've made enough progress to share some initial findings. I'm still new to this code so if anything I say seems incorrect, please call it out. Apologies if this is too verbose. I wanted to show my work in case I get anything wrong. InvestigationI think the motivation for this ticket is the following comment in
With that expectation, we have the following test cases from
I believe this scenario is failing because test results are only saved to the cache under id1 and id2 after the successful run of a test binary. This can be verified by viewing the logs of the test run and searching for Command 1 is acting on a fresh cache. It misses both levels of the cache lookup, resulting in a compile, link and run of the resulting test binary. The test binary run succeeds, so the test results are saved to the cache under id1 (linker inputs) and id2 (test binary). Command 2 hits the cache on the linker inputs, since the inputs are the same as Command 1. A hit on linker inputs means we skip invoking the linker and immediately write the cached test output instead. Command 3 missing the cache on the linker inputs (id1) because they don't include Command 4 misses the cache on linker inputs because Command 3 never saved results into its id1. With that miss, it must invoke the linker, which fails the test. It hits on id2, resulting in Next StepsI think I've found the cause of this specific test case failure, but I recognize that this ticket may intend to cover broader cases which I haven't considered. For this single case, I experimented with calling It may be worth considering whether I hope this information helps. If solving this single case is valuable, I'm happy to take a pass at a fix. I'll wait for feedback from @bcmills or the Go team before doing any more work though. I'd like to help move this issue forward to progress #23565 but I don't mean to overtake an issue that already has an assignee. TL;DR Test results are only saved to the cache when after a successful test binary run. The test case added in this issue hits the cache on id2 (test binary), so it never runs the test binary and therefore never saves the cached test results under id1 (linker inputs). Since a hit on id2 never saves results to the cache under its linker inputs, subsequent runs of the same command will still invoke the linker. I'm not sure whether this is the only issue with extra linking to retrieve cached results, but I believe it's the cause of the case provided. |
This may or may not be relevant, but while doing some other work in cmd/go/internal/work I noticed that the It does attempt a cache lookup, but if never puts anything in the cache presumably that is always a miss. |
Adding the following extra assertions to
cmd/go/testdata/script_build_cache_output.txt
causes the test to fail at the! stderr 'link(\.exe"?)? -'
assertion:Note that both
ok p (cached)
assertions are passing, so this means that under some circumstances we are printing a test's output as “cached” but re-invoking the linker for the test anyway. There is some special-case code incmd/go/internal/test
(added in CL 75631) that attempts to prevent exactly this situation; it isn't yet clear to me why it isn't working.(CC @matloob)
The text was updated successfully, but these errors were encountered: