Infinite hang with CodeChecker on clang without analyser
Describe the bug
If the clang binary used from PATH is built without Clang Static Analyzer, the fetching of checkers hangs infinitely.
CodeChecker version Irrelevant, but exists with 6.11.
To Reproduce Steps to reproduce the behaviour:
- Build LLVM/Clang without ClangSA:
cmake ... -DCLANG_ENABLE_STATIC_ANALYZER=OFF - Put the
Build/binintoPATH - Run something from CodeChecker that has to fetch checkers:
checkers,analyze. - Wait infinitely.
- See error
Expected behaviour Fetch that there are no ClangSA checkers in the list, but do not hang.
Desktop (please complete the following information)
- OS: Linux
Additional context
The issue is due to Clang dumping checker list by calling clang++ -cc1 -analyzer-checker-help. If there is a static analyzer, this dumps the checker list and early returns — but if there is no ClangSA built, the call is "equivalent" to calling clang++ -cc1 which will wait for preprocessed text on the standard input.
In case the standard input is not the tty stdin, but a file, e.g. calling: echo "" | clang -cc1 -analyzer-checker-help
- when there is ClangSA built: same output as usual
- when there is no ClangSA: output is an empty string, but the binary exits immediately and without side effects seemingly.
The issue might need to be fixed within Clang, in addition, because it is bad behaviour there that it starts waiting for stdin...
It's called via subprocess.check_output, so timeout param can be used to fix the hang.
https://docs.python.org/3/library/subprocess.html#subprocess.check_output
Is timeout a good choice? The problem with timeouts is that we can never know what's sensible. If we set it to, let's say, 10 seconds, but the machine the tool is running on is so loaded (or has network-mounted storage?) that loading the checker list (for example if plugins are used) would take 15 seconds, it'll falsely say that there are no checkers.
Another interesting thing: I tried disabling clangsa by specifying --analyzers clang-tidy to the analyze command but it still tries to access the clang binary (for some resource dir printing stuff) and also tries getting the checkers, resulting in this hang.
(Bump: I ran into this thing again today. 😬)