Skip to content
Snippets Groups Projects
  1. Mar 24, 2025
    • Justin Vreeland's avatar
      db: Ensure mtime isn't set on fstat failure to workaround rosetta2 issue · 445338b4
      Justin Vreeland authored
      We've discovered an issue with in apk when using Rosetta2 with wolfi that was surfaced
      by f3f239ac: apk, db: rework dbopts cache_max_age default handling.  With the new
      settings apk now hits an fstatat conditional where it didn't before.  As far as I can tell
      this failure is expected and shouldn't be a problem. It only is because the code
      continues to rely out the buffer that was passed in to contain clean
      values. On Rosetta2 with wolfi the st buffer is no longer clean out after the call to fstatat.
      
      This issue only occurs if cache_max_age is positive, and `/var/cache/apk`
      is empty.  This issue can be seen below:
      
      ```
      a549fa77b74f:/apk-tools# apk --help | head -1
      apk-tools 2.14.10, compiled for x86_64.
      a549fa77b74f:/apk-tools# apk update
      fetch https://packages.wolfi.dev/os/x86_64/APKINDEX.tar.gz
      WARNING: opening from cache https://packages.wolfi.dev/os: No such file or directory
      2 unavailable, 0 stale; 83 distinct packages available
      
      a549fa77b74f:/apk-tools# apk update --cache-max-age 0
      fetch https://packages.wolfi.dev/os/x86_64/APKINDEX.tar.gz
       [https://packages.wolfi.dev/os]
      OK: 144415 distinct packages available
      
      a549fa77b74f:/apk-tools# apk update
       [https://packages.wolfi.dev/os]
      OK: 144415 distinct packages available
      
      a549fa77b74f:/apk-tools# apk update --cache-max-age 1
       [https://packages.wolfi.dev/os]
      OK: 144415 distinct packages available
      
      a549fa77b74f:/apk-tools# rm /var/cache/apk/*
      
      a549fa77b74f:/apk-tools# apk update
      fetch https://packages.wolfi.dev/os/x86_64/APKINDEX.tar.gz
      WARNING: opening from cache https://packages.wolfi.dev/os: No such file or directory
      2 unavailable, 0 stale; 83 distinct packages available
      ```
      
      Some debug output with Rosetta2
      
      ```
      a549fa77b74f:/apk-tools# LD_PRELOAD=`pwd`/src/libapk.so ./src/apk update --cache-max-age 1
      st_mtime pre fstat: 0
      cache_max_age=60
      ferr: -1, tmperr: 2
      st_mtime post fstat: 140737472955232
      fetch https://packages.wolfi.dev/os/x86_64/APKINDEX.tar.gz
      WARNING: opening from cache https://packages.wolfi.dev/os: No such file or directory
      2 unavailable, 0 stale; 83 distinct packages available
      a549fa77b74f:/apk-tools# git diff > /test.patch
      a549fa77b74f:/apk-tools# ps aux | grep rosetta
          1 root      0:02 {sh} /run/rosetta/rosetta /bin/sh /bin/sh -l
      15816 root      0:00 {grep} /run/rosetta/rosetta /usr/bin/grep grep rosetta
      ```
      
      Some debug output without Rosetta2
      
      ```
      /apk-tools # LD_PRELOAD=`pwd`/src/libapk.so ./src/apk update --cache-max-age 1
      st_mtime pre fstat: 0
      cache_max_age=60
      ferr: -1, tmperr: 2
      st_mtime post fstat: 0
      fetch https://packages.wolfi.dev/os/x86_64/APKINDEX.tar.gz
       [https://packages.wolfi.dev/os]
      OK: 144391 distinct packages available
      /apk-tools # ps aux | grep rosetta
       2438 root      0:00 grep rosetta
      ```
      
      I cannot reproduce this with Alpine. In fact the st buffer remains clean
      with Alpine. I believe the real issue is with rosetta2 & glibc not
      actually apk but it seems reasonable not to rely on the buffer from
      a failed system call as a solution for now.
      Unverified
      445338b4
  2. Feb 21, 2025
  3. Feb 13, 2025
  4. Feb 04, 2025
  5. Jan 29, 2025
  6. Jan 14, 2025
  7. Jan 13, 2025
  8. Jan 06, 2025
  9. Dec 28, 2024
  10. Dec 27, 2024
  11. Dec 12, 2024
  12. Dec 09, 2024
  13. Dec 05, 2024
  14. Dec 03, 2024
  15. Nov 29, 2024
  16. Nov 01, 2024
  17. Oct 29, 2024
  18. Oct 16, 2024
  19. Aug 30, 2024
Loading