Skip to content

Fall back to direct cache write if tempfile creation on the same fs fails#2369

Merged
sylvestre merged 11 commits into
mozilla:mainfrom
myzhang1029:main
Jun 4, 2026
Merged

Fall back to direct cache write if tempfile creation on the same fs fails#2369
sylvestre merged 11 commits into
mozilla:mainfrom
myzhang1029:main

Conversation

@myzhang1029

Copy link
Copy Markdown
Contributor

Please see #2288 for the discussion.

Comment thread src/cache/cache.rs Outdated
@codecov-commenter

codecov-commenter commented Apr 15, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.27626% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.32%. Comparing base (b81fdbb) to head (3804ba5).

Files with missing lines Patch % Lines
src/cache/cache_io.rs 95.51% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2369      +/-   ##
==========================================
+ Coverage   73.58%   74.32%   +0.73%     
==========================================
  Files          70       70              
  Lines       38220    39471    +1251     
==========================================
+ Hits        28125    29337    +1212     
- Misses      10095    10134      +39     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sylvestre

Copy link
Copy Markdown
Collaborator

would it be possible to add a test to make sure we don't regress in the future?
thanks

@myzhang1029

Copy link
Copy Markdown
Contributor Author

@sylvestre
I am not familiar with a similar concept under Windows, so is it fine if I hardcode a test for something under /dev and make this test case cfg(unix)?

@myzhang1029

myzhang1029 commented May 26, 2025

Copy link
Copy Markdown
Contributor Author

Rebased on main and added two tests. Both tests succeed on the branch and fail before the patch.

I am not entirely sure if the use of /dev/fd is portable enough to all the unices that Rust and sccache intend to support. Please feel free to skip that one if not.

@sylvestre

Copy link
Copy Markdown
Collaborator

could you please add high level tests in https://github.com/mozilla/sccache/blob/main/tests/system.rs too ? thanks

like

fn test_sccache_command(preprocessor_cache_mode: bool) {

@myzhang1029

myzhang1029 commented Jun 16, 2025

Copy link
Copy Markdown
Contributor Author

@sylvestre Sorry for the delayed response. I am planning to test this by adding two functions that are similar to test_basic_compile in system.rs.

One of them should test /dev/null and the other for /dev/stdout (AssertCmd::assert seems to capture stdout already --- better approach maybe?) They would:

  1. Compiles a file
  2. Repeats the compilation command
  3. Check that both commands succeed and that #miss and #hit are both 1.

@myzhang1029

myzhang1029 commented Jun 16, 2025

Copy link
Copy Markdown
Contributor Author

On a second thought, I have a question:

I think I named the PR a bit too narrow. Maybe like

Fall back to direct cache write if parent directory is not writable

I was think of reframing the PR this way, because this way, we don't have to hardcode /dev anymore. We can instead:

  1. run the first compilation command
  2. chmod u-w the destination dir
  3. run the second (cached) pass

Comment thread src/cache/cache.rs Outdated
@myzhang1029

Copy link
Copy Markdown
Contributor Author

@AJIOB I have pushed the change. Sorry for the delay.

@myzhang1029

Copy link
Copy Markdown
Contributor Author

There is an issue with the tests: we use the same INPUT, so the cache stats depend on the previous tests. I feel like it would become a maintenance disaster to hardcode the expected stats into the tests in this case. Would it be acceptable to put a pair of start_local_daemon stop_local_daemon in each test?

@myzhang1029

Copy link
Copy Markdown
Contributor Author

CI should work now.

I have relaxed one more error handling: in the case that same-fs file creation fails, we also allow chmod to fail.

@AJIOB

AJIOB commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

Hi @myzhang1029 ,

I face with that error
As a result, the OpenSSL Perl incorrectly generates assembly file.

Do you have some plans to actualize the PR?

@myzhang1029

Copy link
Copy Markdown
Contributor Author

Hello @AJIOB

Is my understanding correct that this patch would fix that error you mentioned?

Lots has happened in the repo and let me work on this today!

@AJIOB

AJIOB commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

I hope it helps.

In the trace mode I have:

[2026-03-11T12:18:02Z DEBUG sccache::compiler::compiler] Found gcc
[2026-03-11T12:18:02Z TRACE sccache::server] Inserting POSSIBLY PROXIED cache map info for "/usr/bin/gcc"
[2026-03-11T12:18:02Z DEBUG sccache::server] check_compiler: Supported compiler
[2026-03-11T12:18:02Z DEBUG sccache::server] parse_arguments: Ok: ["-Wa,-v", "-c", "-o", "/dev/null", "-x", "assembler", "/dev/null"]
[2026-03-11T12:18:02Z DEBUG sccache::compiler::compiler] [null]: get_cached_or_compile: ["-Wa,-v", "-c", "-o", "/dev/null", "-x", "assembler", "/dev/null"]
[2026-03-11T12:18:02Z TRACE sccache::util] Hashed 0 files in 0.000 s
[2026-03-11T12:18:02Z DEBUG sccache::compiler::c] generate_hash_key: Disabling preprocessor cache because assembler language doesn't need C preprocessing
[2026-03-11T12:18:02Z DEBUG sccache::compiler::compiler] [null]: generate_hash_key took 0.000 s
[2026-03-11T12:18:02Z DEBUG sccache::compiler::compiler] [null]: Hash key: 11b765162fadb5068b7bb35ddec6a07e17f458f37cef7c0d884955a66981f15c
[2026-03-11T12:18:02Z TRACE sccache::cache::disk] DiskCache::get(11b765162fadb5068b7bb35ddec6a07e17f458f37cef7c0d884955a66981f15c)
[2026-03-11T12:18:02Z DEBUG sccache::compiler::compiler] [null]: Cache hit in 0.014 s
[2026-03-11T12:18:02Z ERROR sccache::server] ["null"] fatal error: Permission denied (os error 13) at path "/dev/.tmp9gyxnV"
[2026-03-11T12:18:02Z ERROR sccache::server] ["null"] 	Permission denied (os error 13) at path "/dev/.tmp9gyxnV"

@AJIOB

AJIOB commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

P.S. Just an easy-to-reproduce test on the latest sccache 0.14.0:

$ gcc -Wa,-v -c -o /dev/null -x assembler /dev/null
GNU assembler version 2.42 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.42
$ sccache gcc -Wa,-v -c -o /dev/null -x assembler /dev/null
sccache: encountered fatal error
sccache: error: Permission denied (os error 13) at path "/dev/.tmpNJtyLa"
sccache: caused by: Permission denied (os error 13) at path "/dev/.tmpNJtyLa"

@AJIOB

AJIOB commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Hi @myzhang1029 ,

Do you have any updates?

@myzhang1029

Copy link
Copy Markdown
Contributor Author

Sorry for the delay as my area was hit by some severe weather.

This time is largely just rebasing the code and resolving conflicts, but this version should already fix the openssl building error you mentioned. What is left is to figure out the tests properly.

@AJIOB

AJIOB commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

Hi @sylvestre,

Is this PR OK to you?

@myzhang1029
myzhang1029 force-pushed the main branch 2 times, most recently from eac34f9 to 1116960 Compare March 15, 2026 14:37
@myzhang1029

myzhang1029 commented Mar 15, 2026

Copy link
Copy Markdown
Contributor Author

Moved the unit tests to cache_io.rs since it uses a private interface.
I've moved the integration tests to branch pr2369-tests since I realized that the expected constants (counts) depend on the platform.

Edit: The integration tests have been merged back.

@myzhang1029

Copy link
Copy Markdown
Contributor Author

Just gonna rebase onto main to see if the new tests still work :)

@AJIOB

AJIOB commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Hi @drahnr ,

Is it OK for you?

myzhang1029 and others added 7 commits April 25, 2026 14:36
Signed-off-by: Zhang Maiyun <me@maiyun.me>
Fixes mozilla#2288

The new logic tries to write to a temp file and atomically move it as
before, but if a temp file cannot be created, it falls back to writing
directly to the final location. In the latter case, we also ignore
errors from `set_file_mode`.

Signed-off-by: Zhang Maiyun <me@maiyun.me>
Co-authored-by: Alex Overchenko <aleksandr9809@gmail.com>
In addition, when `/dev/fd/{fd}` doesn't actually exist (e.g. FreeBSD
without `fdescfs`), skip the test to extract to `/dev/fd/{fd}`.

Signed-off-by: Zhang Maiyun <me@maiyun.me>
@myzhang1029

Copy link
Copy Markdown
Contributor Author

another rebase onto main, mainly for checking compatibility with #2581

Comment thread src/cache/cache_io.rs
Comment thread tests/system.rs Outdated
@myzhang1029
myzhang1029 force-pushed the main branch 2 times, most recently from a8f7502 to bf045fa Compare April 25, 2026 20:29
@myzhang1029

Copy link
Copy Markdown
Contributor Author

I got my hands on a windows machine and it turned out I simplified the NUL mess. Now fixed.

@myzhang1029

Copy link
Copy Markdown
Contributor Author

@drahnr The testsuites seem to work on my FreeBSD VM. Could you please have a look? Thanks!

@myzhang1029

Copy link
Copy Markdown
Contributor Author

@drahnr @sylvestre Hi Both,

How do you feel about merging this patch?

@sylvestre
sylvestre merged commit 7deff49 into mozilla:main Jun 4, 2026
91 of 92 checks passed
eleboucher pushed a commit to eleboucher/towonel that referenced this pull request Jun 19, 2026
….0) (#36)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [mozilla/sccache](https://github.com/mozilla/sccache) | minor | `0.15.0` → `0.16.0` |

---

### Release Notes

<details>
<summary>mozilla/sccache (mozilla/sccache)</summary>

### [`v0.16.0`](https://github.com/mozilla/sccache/releases/tag/v0.16.0)

[Compare Source](mozilla/sccache@v0.15.0...v0.16.0)

##### sccache 0.16.0

##### Summary

sccache 0.16.0 is a smaller, stabilizing release on top of 0.15.0's multi-tier caching work, with a few new capabilities:

- **Read-only backends**: Any storage backend can now be marked read-only, not just a select few ([#&#8203;2705](mozilla/sccache#2705)).
- **Remote execution on aarch64**: Distributed/remote execution now works on Linux aarch64, including fixes for `ldd` output parsing and toolchain packaging on non-x86\_64 Linux ([#&#8203;2668](mozilla/sccache#2668)).
- **CUDA**: `nvcc`'s `--dependency-output` argument is now handled ([#&#8203;2708](mozilla/sccache#2708)).
- **Resilience**: Fall back to a direct cache write when tempfile creation on the same filesystem fails ([#&#8203;2369](mozilla/sccache#2369)), and give a meaningful error when a multi-level chain references a backend that wasn't compiled in ([#&#8203;2695](mozilla/sccache#2695)).
- **Client efficiency**: The client and dist-client now use a single-threaded tokio runtime, avoiding a thread explosion when many short-lived clients run on many-core hosts ([#&#8203;2704](mozilla/sccache#2704)).
- **Correctness**: Strip `SCCACHE_BASEDIRS` from escaped-backslash paths on Windows ([#&#8203;2736](mozilla/sccache#2736)), ignore empty-set environment values in config ([#&#8203;2639](mozilla/sccache#2639)), and avoid the sccache wrapper when resolving the real compiler ([#&#8203;2720](mozilla/sccache#2720)).
- **Security/logging**: JWT keys and cert digests are now base64-encoded in logs ([#&#8203;2712](mozilla/sccache#2712)), plus general logging improvements ([#&#8203;2734](mozilla/sccache#2734)).

Welcome to 4 new contributors!

##### Features

- feat: all backends support making them as read-only by [@&#8203;AJIOB](https://github.com/AJIOB) in [#&#8203;2705](mozilla/sccache#2705)
- Enable RE on Linux-aarch64 by [@&#8203;malfet](https://github.com/malfet) in [#&#8203;2668](mozilla/sccache#2668)
- feat(nvcc): support argument: `--dependency-output` by [@&#8203;ZRHann](https://github.com/ZRHann) in [#&#8203;2708](mozilla/sccache#2708)
- feat: avoid sccache wrapper when resolving compiler by [@&#8203;iTrooz](https://github.com/iTrooz) in [#&#8203;2720](mozilla/sccache#2720)
- Fall back to direct cache write if tempfile creation on the same fs fails by [@&#8203;myzhang1029](https://github.com/myzhang1029) in [#&#8203;2369](mozilla/sccache#2369)
- Don't wait depfiles for gcc/clang preprocessed inputs by [@&#8203;AJIOB](https://github.com/AJIOB) in [#&#8203;2665](mozilla/sccache#2665)

##### Fixes

- fix: strip SCCACHE\_BASEDIRS from escaped-backslash paths on Windows by [@&#8203;rconde01](https://github.com/rconde01) in [#&#8203;2736](mozilla/sccache#2736)
- fix: ignore empty-set environment values for config by [@&#8203;AJIOB](https://github.com/AJIOB) in [#&#8203;2639](mozilla/sccache#2639)
- fix: handle disabled cache backend features in multilevel chain by [@&#8203;cryptomilk](https://github.com/cryptomilk) in [#&#8203;2695](mozilla/sccache#2695)
- fix: use single-threaded tokio runtime in sccache (dist-)client by [@&#8203;AJIOB](https://github.com/AJIOB) in [#&#8203;2704](mozilla/sccache#2704)
- fix: add newline when printing dist-status to stdout by [@&#8203;iTrooz](https://github.com/iTrooz) in [#&#8203;2710](mozilla/sccache#2710)

##### Logging

- chore: encode jwt key and cert digest with base64 in logs by [@&#8203;iTrooz](https://github.com/iTrooz) in [#&#8203;2712](mozilla/sccache#2712)
- Slightly improve logging by [@&#8203;glandium](https://github.com/glandium) in [#&#8203;2734](mozilla/sccache#2734)

##### Cleanup

- chore: make clippy happy by [@&#8203;AJIOB](https://github.com/AJIOB) in [#&#8203;2727](mozilla/sccache#2727)
- Extract new\_client\_runtime() helper to DRY up client runtime creation by [@&#8203;sylvestre](https://github.com/sylvestre) in [#&#8203;2744](mozilla/sccache#2744)

##### New Contributors

- [@&#8203;ZRHann](https://github.com/ZRHann) made their first contribution in [#&#8203;2708](mozilla/sccache#2708)
- [@&#8203;myzhang1029](https://github.com/myzhang1029) made their first contribution in [#&#8203;2369](mozilla/sccache#2369)
- [@&#8203;malfet](https://github.com/malfet) made their first contribution in [#&#8203;2668](mozilla/sccache#2668)
- [@&#8203;rconde01](https://github.com/rconde01) made their first contribution in [#&#8203;2736](mozilla/sccache#2736)

**Full Changelog**: <mozilla/sccache@v0.15.0...v0.16.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9naXRodWItcmVsZWFzZSIsInR5cGUvbWlub3IiXX0=-->

Reviewed-on: https://codeberg.org/towonel/towonel/pulls/36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants