mozilla / sccache

Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
Apache License 2.0
5.74k stars 542 forks source link

Fatal error on cache retrieval #1015

Open lodegaard opened 3 years ago

lodegaard commented 3 years ago

Sccache version: 0.2.15 Os: CentOS-7 Compiler: clang-11

When the compile output is set to a folder where sccache doesn't have write permissions, there is a fatal error when attempting to retrieve an entry from the cache. Some projects, like musl, uses compilation with output to /dev/null to probe the compiler for certain features during configuration.

This is the sccache log output during compilation:

[2021-07-01T06:20:09Z TRACE sccache::server] incoming connection
[2021-07-01T06:20:09Z TRACE sccache::server] handle_client
[2021-07-01T06:20:09Z DEBUG sccache::server] handle_client: compile
[2021-07-01T06:20:09Z TRACE sccache::server] compiler_info
[2021-07-01T06:20:09Z TRACE sccache::server] compiler_info cache miss
[2021-07-01T06:20:09Z TRACE sccache::compiler::compiler] detect_compiler: /opt/llvm-11/bin/clang
[2021-07-01T06:20:09Z TRACE sccache::compiler::compiler] detect_c_compiler
[2021-07-01T06:20:09Z TRACE sccache::compiler::compiler] compiler Some("/opt/llvm-11/bin/clang" "-E" "/tmp/sccacheo4tXk0/testfile.c")
[2021-07-01T06:20:09Z DEBUG sccache::compiler::compiler] Found clang
[2021-07-01T06:20:09Z TRACE sccache::server] Inserting POSSIBLY PROXIED cache map info for "/opt/llvm-11/bin/clang"
[2021-07-01T06:20:09Z DEBUG sccache::server] check_compiler: Supported compiler
[2021-07-01T06:20:09Z DEBUG sccache::server] parse_arguments: Ok: ["-c", "tmp.c", "-o", "/dev/null"]
[2021-07-01T06:20:09Z DEBUG sccache::compiler::compiler] [null]: get_cached_or_compile: ["-c", "tmp.c", "-o", "/dev/null"]
[2021-07-01T06:20:09Z TRACE sccache::compiler::gcc] preprocess
[2021-07-01T06:20:09Z TRACE sccache::compiler::gcc] preprocess: Some("/opt/llvm-11/bin/clang" "-x" "c" "-E" "-P" "tmp.c")
[2021-07-01T06:20:09Z TRACE sccache::compiler::c] [null]: Preprocessor output is 15 bytes
[2021-07-01T06:20:09Z TRACE sccache::util] Hashed 0 files in 0.022 s
[2021-07-01T06:20:09Z DEBUG sccache::compiler::compiler] [null]: generate_hash_key took 0.022 s
[2021-07-01T06:20:09Z TRACE sccache::compiler::compiler] [null]: Hash key: e1d26e088e48dca8f82af00ef9c69a95cb05f0070fae48fca1ec3d4cb7b2d7e5
[2021-07-01T06:20:09Z TRACE sccache::cache::disk] DiskCache::get(e1d26e088e48dca8f82af00ef9c69a95cb05f0070fae48fca1ec3d4cb7b2d7e5)
[2021-07-01T06:20:09Z TRACE sccache::cache::disk] DiskCache::get(e1d26e088e48dca8f82af00ef9c69a95cb05f0070fae48fca1ec3d4cb7b2d7e5): FileNotInCache
[2021-07-01T06:20:09Z DEBUG sccache::compiler::compiler] [null]: Cache miss in 0.000 s
[2021-07-01T06:20:09Z TRACE sccache::compiler::gcc] compile
[2021-07-01T06:20:09Z DEBUG sccache::compiler::compiler] [null]: Compiling locally
[2021-07-01T06:20:09Z DEBUG sccache::compiler::compiler] [null]: Compiled in 0.017 s, storing in cache
[2021-07-01T06:20:09Z TRACE sccache::cache::disk] DiskCache::finish_put(e1d26e088e48dca8f82af00ef9c69a95cb05f0070fae48fca1ec3d4cb7b2d7e5)
[2021-07-01T06:20:09Z TRACE sccache::server] CompileFinished retcode: exit code: 0
[2021-07-01T06:20:09Z DEBUG sccache::compiler::compiler] [null]: Stored in cache successfully!
[2021-07-01T06:20:09Z DEBUG sccache::server] [null]: Cache write finished in 0.000 s
[2021-07-01T06:20:37Z TRACE sccache::server] incoming connection
[2021-07-01T06:20:37Z TRACE sccache::server] handle_client
[2021-07-01T06:20:37Z DEBUG sccache::server] handle_client: compile
[2021-07-01T06:20:37Z TRACE sccache::server] compiler_info
[2021-07-01T06:20:37Z TRACE sccache::server] compiler_info cache hit
[2021-07-01T06:20:37Z DEBUG sccache::server] check_compiler: Supported compiler
[2021-07-01T06:20:37Z DEBUG sccache::server] parse_arguments: Ok: ["-c", "tmp.c", "-o", "/dev/null"]
[2021-07-01T06:20:37Z DEBUG sccache::compiler::compiler] [null]: get_cached_or_compile: ["-c", "tmp.c", "-o", "/dev/null"]
[2021-07-01T06:20:37Z TRACE sccache::compiler::gcc] preprocess
[2021-07-01T06:20:37Z TRACE sccache::compiler::gcc] preprocess: Some("/opt/llvm-11/bin/clang" "-x" "c" "-E" "-P" "tmp.c")
[2021-07-01T06:20:37Z TRACE sccache::compiler::c] [null]: Preprocessor output is 15 bytes
[2021-07-01T06:20:37Z TRACE sccache::util] Hashed 0 files in 0.017 s
[2021-07-01T06:20:37Z DEBUG sccache::compiler::compiler] [null]: generate_hash_key took 0.017 s
[2021-07-01T06:20:37Z TRACE sccache::compiler::compiler] [null]: Hash key: e1d26e088e48dca8f82af00ef9c69a95cb05f0070fae48fca1ec3d4cb7b2d7e5
[2021-07-01T06:20:37Z TRACE sccache::cache::disk] DiskCache::get(e1d26e088e48dca8f82af00ef9c69a95cb05f0070fae48fca1ec3d4cb7b2d7e5)
[2021-07-01T06:20:37Z DEBUG sccache::compiler::compiler] [null]: Cache hit in 0.000 s
[2021-07-01T06:20:37Z ERROR sccache::server] ["null"] fatal error: Permission denied (os error 13) at path "/dev/.tmp8jzDrb"
[2021-07-01T06:20:37Z ERROR sccache::server] ["null"]         Permission denied (os error 13) at path "/dev/.tmp8jzDrb"

As seen, the compilation works when there is a cache miss, but fails when there is an entry in the cache. Steps to reproduce:

  1. Create a c source file, tmp.c, with this content: typedef int x;
  2. Run the compile command twice: sccache clang -c tmp.c -o /dev/null
luser commented 3 years ago

We actually have code to special-case this same situation with MSVC on Windows, where you might pass -Fonul: https://github.com/mozilla/sccache/blob/3f318a8675e4c3de4f5e8ab2d086189f2ae5f5cf/src/compiler/msvc.rs#L483