Skip to content

fix: handle filesystem errors during lora and upscaler cache scan (#1920) - #2064

Merged
leejet merged 3 commits into
leejet:masterfrom
Yi-111-a:fix/1920-fix-directory-scan-exception
Sep 27, 2026
Merged

leejet merged 3 commits into
leejet:masterfrom
Yi-111-a:fix/1920-fix-directory-scan-exception

Conversation

@Yi-111-a

Copy link
Copy Markdown
Contributor

Resolves #1920.

Problem

In refresh_lora_cache and refresh_upscaler_cache (examples/server/runtime.cpp), directory traversal checked entries using unguarded entry.is_regular_file(), entry.file_size(), and unhandled directory iteration.
When the directory contains restricted entries, broken symlinks, special mounts (e.g. /proc/1/map_files inside Docker containers or systemd overlays), entry.is_regular_file() throws an uncaught std::filesystem::filesystem_error (Operation not permitted / Permission denied).
This escaped to the HTTP server handler, causing /sdcpp/v1/capabilities and /sdcpp/v1/img_gen to fail with 500 Internal Server Error and breaking the WebUI.
Additionally, the runtime stage of the Dockerfiles did not set WORKDIR, defaulting to / where --lora-model-dir . scanned the entire Linux root filesystem.

Fix

  1. In examples/server/runtime.cpp:
    • Use the std::error_code overloads for is_regular_file, file_size, last_write_time, and absolute.
    • Use fs::directory_options::skip_permission_denied for upscalers directory iteration as well.
    • Wrap scanning in try ... catch (const std::exception& e) with warning logs so an inaccessible entry or directory never crashes the request handler or returns a 500.
  2. In docker/Dockerfile*:
    • Add WORKDIR /sd.cpp in the runtime stage of all Dockerfiles so the working directory defaults to /sd.cpp rather than container root /.

Fixes #1920

@leejet
leejet merged commit 9947eeb into leejet:master Sep 27, 2026
9 checks passed
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.

[Bug] Docker WebUI 500 from /sdcpp/v1/capabilities

2 participants