llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[BUILD] Race condition during build/testing for check-clang/check-clang-tools

Open AaronBallman opened this issue 1 year ago • 10 comments

[6099/6110] Running clang_tools regression tests
llvm-lit.py: C:\_work\llvm-project\llvm-project\llvm\utils\lit\lit\llvm\config.py:57: note: using lit tools: C:\Program Files\Git\usr\bin
llvm-lit.py: C:\_work\llvm-project\llvm-project\llvm\utils\lit\lit\llvm\config.py:520: note: using clang: c:\_work\llvm-project\llvm-project\build\bin\clang.exe
llvm-lit.py: C:\_work\llvm-project\llvm-project\llvm\utils\lit\lit\llvm\config.py:312: fatal: Couldn't find the include dir for Clang ('c:\_work\llvm-project\llvm-project\build\bin\clang.exe')
c:\_work\llvm-project\llvm-project\build\bin\clang.exe
[6101/6110] Linking CXX executable bin\obj2yaml.exe
FAILED: tools/clang/tools/extra/CMakeFiles/check-clang-tools 
cmd.exe /C "cd /D C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra && C:\Python39\python.exe C:/_work/llvm-project/llvm-project/build/./bin/llvm-lit.py -v --xunit-xml-output C:/_work/llvm-project/llvm-project/build/test-results.xml --use-unique-output-file-name --timeout=1200 --time-tests C:/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/include-cleaner/test C:/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/clangd/test/../unittests C:/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/clangd/test C:/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test"
[6103/6110] Linking CXX executable bin\clang.exe

It looks like we try to run the clang-tools-extra regression tests which seem to be looking for clang.exe which isn't yet built.

Some examples of this in the wild include: https://github.com/llvm/llvm-project/actions/runs/15875229617/job/44761115591?pr=145679 https://github.com/llvm/llvm-project/actions/runs/15860875108/job/44717506023?pr=143424

AaronBallman avatar Jun 25 '25 13:06 AaronBallman

@llvm/issue-subscribers-infrastructure

Author: Aaron Ballman (AaronBallman)

``` [6099/6110] Running clang_tools regression tests llvm-lit.py: C:\_work\llvm-project\llvm-project\llvm\utils\lit\lit\llvm\config.py:57: note: using lit tools: C:\Program Files\Git\usr\bin llvm-lit.py: C:\_work\llvm-project\llvm-project\llvm\utils\lit\lit\llvm\config.py:520: note: using clang: c:\_work\llvm-project\llvm-project\build\bin\clang.exe llvm-lit.py: C:\_work\llvm-project\llvm-project\llvm\utils\lit\lit\llvm\config.py:312: fatal: Couldn't find the include dir for Clang ('c:\_work\llvm-project\llvm-project\build\bin\clang.exe') c:\_work\llvm-project\llvm-project\build\bin\clang.exe [6101/6110] Linking CXX executable bin\obj2yaml.exe FAILED: tools/clang/tools/extra/CMakeFiles/check-clang-tools cmd.exe /C "cd /D C:\_work\llvm-project\llvm-project\build\tools\clang\tools\extra && C:\Python39\python.exe C:/_work/llvm-project/llvm-project/build/./bin/llvm-lit.py -v --xunit-xml-output C:/_work/llvm-project/llvm-project/build/test-results.xml --use-unique-output-file-name --timeout=1200 --time-tests C:/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/include-cleaner/test C:/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/clangd/test/../unittests C:/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/clangd/test C:/_work/llvm-project/llvm-project/build/tools/clang/tools/extra/test" [6103/6110] Linking CXX executable bin\clang.exe ```

It looks like we try to run the clang-tools-extra regression tests which seem to be looking for clang.exe which isn't yet built.

Some examples of this in the wild include: https://github.com/llvm/llvm-project/actions/runs/15875229617/job/44761115591?pr=145679 https://github.com/llvm/llvm-project/actions/runs/15860875108/job/44717506023?pr=143424

llvmbot avatar Jun 25 '25 13:06 llvmbot

@cmtice @lnihlen Is the current on call able to investigate this? It could be relatively recent and might just be a CMake missing dependency, but impacts reliability a decent amount.

Not entirely sure it’s in scope for the rotation though given it’s not an infrastructure issue.

boomanaiden154 avatar Jun 25 '25 14:06 boomanaiden154

@Keenuts is primary this week. I'll try to take a look in a bit myself.

lnihlen avatar Jun 25 '25 14:06 lnihlen

Looks like the issue was already existing? But since https://github.com/llvm/llvm-project/pull/144033 seems like the CI now runs this, hence the failure showing

Keenuts avatar Jun 25 '25 16:06 Keenuts

Not sure why this is happening yet. But what the flakiness I observe, even locally on linux tells me there is some race-condition

Keenuts avatar Jun 25 '25 17:06 Keenuts

Hi, I renamed the issuer to reflect what this is about. I haven't found the culprit, but at least we know this is not an infrastructure issue.

This can be reproduced locally on linux (if lucky since flaky) on a clean build with:

cmake -S ./llvm -B repro -D 'LLVM_ENABLE_PROJECTS=clang;clang-tools-extra;llvm' -G Ninja -D CMAKE_BUILD_TYPE=Release -D LLVM_ENABLE_ASSERTIONS=ON -D LLVM_BUILD_EXAMPLES=ON -D COMPILER_RT_BUILD_LIBFUZZER=OFF -D 'LLVM_LIT_ARGS=-v --use-unique-output-file-name --timeout=1200 --time-tests' -D COMPILER_RT_BUILD_ORC=OFF -D MLIR_ENABLE_BINDINGS_PYTHON=ON -D LLVM_PARALLEL_COMPILE_JOBS=64 -D LLVM_PARALLEL_LINK_JOBS=64 && ninja -C repro check-clang check-clang-tools

Keenuts avatar Jun 26 '25 15:06 Keenuts

It's not actually clang.exe that's missing, it's the output of clang.exe -print-file-name=include that's empty. clang-resource-headers target is in CLANG_TOOLS_TEST_DEPS and I do see Ninja copying the headers into place in the build log so the directory should exist.

petrhosek avatar Jun 27 '25 08:06 petrhosek

@Keenuts Do you have additional reproduction instructions on Linux? I tried doing this in the CI container on a 128-thread machine and couldn't reproduce it after ~10 attempts. It's also interesting that it seems like the only CI failures have been in Windows jobs. I think I'm going to try and reproduce it there next.

boomanaiden154 avatar Jul 07 '25 20:07 boomanaiden154

Some oddities:

  1. check-clang-tools doesn't depend on clang. Running check-clang-tools by itself never builds clang (as expected), and also runs fine. This seems to imply that we're not actually running the fault code path in the lit config logic.
  2. The invocation of clang in the lit config logic seems to be specific to using clang. Given the clang-tools-extra test suite doesn't depend on clang and never uses clang and it runs fine without clang, it seems like the presence of the binary is somehow influencing the lit code execution path which I don't think should be happening.
  3. This reproduces perfectly if I just run ninja check-clang-tools, touch ./bin/clang to create a dummy clang that can't actually execute anything, and then ninja check-clang-tools again. The second check invocation fails in this exact manner. Given this, I'm guessing the race condition is around the clang symlink (or maybe even the binary it points to?) getting created at the same time. It's present but not executable given there's no hard dependency and thus the check fails.

Now to figure out why we would be executing that code path in the first place...

boomanaiden154 avatar Jul 07 '25 23:07 boomanaiden154

@Keenuts Do you have additional reproduction instructions on Linux? I tried doing this in the CI container on a 128-thread machine and couldn't reproduce it after ~10 attempts. It's also interesting that it seems like the only CI failures have been in Windows jobs. I think I'm going to try and reproduce it there next.

I was able to reproduce this quite often on linux, but only when doing a clean build. (128 core, cmake + ninja). But the repro you found seems way more efficient than a clean build.

Keenuts avatar Jul 08 '25 09:07 Keenuts