Skip to content

SCCACHE_S3_RW_MODE=READ_ONLY breaks local disk cache #2773

Closed

Description

@m-pilia

Hi, I was trying to configure sccache to use a multi-level cache with read-only S3 and read-write disk cache (following docs/MultiLevel.md). However, if I set S3 to be read-only, the local disk cache stops working.

To reproduce

I used an environment with latest sccache version (v0.16.0):

FROM ubuntu:24.04

ARG SCCACHE_VERSION=v0.16.0
RUN apt-get update \
    && apt-get install --no-install-recommends -y gcc python3 wget ca-certificates \
    && rm -rf /var/lib/apt/lists/* \
    && wget -q "https://github.com/mozilla/sccache/releases/download/${SCCACHE_VERSION}/sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
    && tar -xf "sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
    && install -m 0755 "sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache" /usr/local/bin/sccache \
    && rm -rf "sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl"*

...

Launched a build with this config:

export SCCACHE_MULTILEVEL_CHAIN=disk,s3
export SCCACHE_S3_RW_MODE=READ_ONLY
export SCCACHE_DIR=~/.cache/sccache
export SCCACHE_CACHE_SIZE=20G
export SCCACHE_BUCKET=<my-bucket>
export SCCACHE_REGION=<my-region>
export SCCACHE_S3_KEY_PREFIX=<my-prefix>


cmake -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache ...
cmake --build ...

The build works but nothing gets written to the local disk cache:

$ du -h ~/.cache/sccache
4.0K    ./preprocessor
8.0K    .

Note that the issue does NOT happen if I use SCCACHE_MULTILEVEL_CHAIN=disk, in that case the local cache gets written normally.

Activity

  1. added a commit that references this issue on Jul 23, 2026
    5348be7
  2. sargunv commented on Jul 24, 2026

    @sargunv

    I just got bit by this as well, glad to see there's already a PR up!

  3. geir-t commented on Aug 6, 2026

    @geir-t

    I also got hit by this one. Hope the PR is OK to merge.

  4. added 2 commits that reference this issue on Aug 6, 2026
    41ad507
    0fd0f0f
  5. Battarshuck commented on Aug 20, 2026

    @Battarshuck

    Same issue with Redis.

  6. garysassano commented on Aug 21, 2026

    @garysassano

    I think this is MultiLevelStorage::check() aggregating the levels with read-only winning, combined with the server wrapping the whole storage when the aggregate says read-only.

    src/cache/multilevel.rs L877-L896 (v0.17.0):

    async fn check(&self) -> Result<CacheMode> {
        let mut result = CacheMode::ReadWrite;
        for (idx, level) in self.levels.iter().enumerate() {
            match level.check().await {
                Ok(CacheMode::ReadOnly) => {
                    result = CacheMode::ReadOnly;   // any read-only level makes the whole chain read-only
                    debug!("Cache level {} is read-only", idx);
                }
                // ...

    So with disk,s3 and SCCACHE_S3_RW_MODE=READ_ONLY, the S3 level reports ReadOnly and the aggregate becomes ReadOnly even though the disk level is writable.

    The server then wraps everything — src/server.rs L489-L491:

    let storage = match cache_mode {
        CacheMode::ReadOnly => Arc::new(ReadOnlyStorage(raw_storage)),
        _ => raw_storage,

    which is why nothing is written to the local disk cache, matching the reported symptom.

    This looks like it wants the opposite aggregation: the chain is writable if any level is writable, since put_raw / write_remaining_levels_async already skip individual read-only levels on their own.

    (I ran into the same code path from a different angle while looking at per-write check() calls in the multi-level backend, filed as #2818.)

  7. FabianSchurig commented on Sep 11, 2026

    @FabianSchurig

    Hi @sylvestre, Hi @trxcllnt,

    we also noticed this bug and were curious if you could merge the fix (open PR) into 0.18.0 or 0.18.1 release, please.
    It seems like a quite common use case for me to have a remote cache updated by CI only while developers should be able to write their local caches without updating the remote.

    If I can support with anything, let me know.

    Thanks in advance!

  8. added a commit that references this issue on Sep 11, 2026
    6089d04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions