Skip to content

fix(mediascanner): prevent indefinite hangs on stale network mounts#549

Merged
wizzomafizzo merged 2 commits intomainfrom
fix/mediascanner-nas-hang
Mar 4, 2026
Merged

fix(mediascanner): prevent indefinite hangs on stale network mounts#549
wizzomafizzo merged 2 commits intomainfrom
fix/mediascanner-nas-hang

Conversation

@wizzomafizzo
Copy link
Member

Summary

  • Wrap filesystem operations (os.Stat, os.ReadDir, os.Lstat, filepath.EvalSymlinks) with context-aware 10s timeouts via a generic doWithTimeout[T] helper, preventing the media scanner from hanging indefinitely on stale NFS/CIFS mounts
  • Introduce dirCache for case-insensitive path lookups during FindPath, reducing repeated filesystem calls
  • Handle SQLite UNIQUE constraint failures gracefully during indexing instead of aborting the entire scan
  • Replace magic phase strings with PhaseDiscovering/PhaseInitializing constants for status reporting
  • Switch GOPROXY from third-party goproxy.io to direct
  • Fix test assertion and cleanup patterns for updated indexing status formula

Wrap filesystem operations (os.Stat, os.ReadDir, os.Lstat,
filepath.EvalSymlinks) with context-aware timeouts to prevent the media
scanner from hanging indefinitely on stale NFS/CIFS mounts. Introduce a
directory cache (dirCache) for case-insensitive path lookups to reduce
repeated filesystem calls during scanning.

Also:
- Handle SQLite UNIQUE constraint failures gracefully during indexing
- Add phase constants (PhaseDiscovering, PhaseInitializing) replacing
  magic strings in status reporting
- Switch GOPROXY from goproxy.io to direct
- Fix test assertion for updated Total calculation formula
@sentry
Copy link

sentry bot commented Mar 4, 2026

Codecov Report

❌ Patch coverage is 63.95349% with 62 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/database/mediascanner/mediascanner.go 46.15% 55 Missing and 1 partial ⚠️
pkg/database/mediascanner/fsutil.go 91.89% 3 Missing ⚠️
pkg/platforms/mister/platform.go 50.00% 2 Missing ⚠️
pkg/api/methods/media.go 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

EvalSymlinks resolves all symlinks in the path including those in the
temp directory itself (e.g. /var -> /private/var on macOS, 8.3 short
names on Windows). Compare against the resolved expected path instead
of the raw t.TempDir() path.
@wizzomafizzo wizzomafizzo merged commit dce232c into main Mar 4, 2026
10 checks passed
@wizzomafizzo wizzomafizzo deleted the fix/mediascanner-nas-hang branch March 4, 2026 07:04
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.

1 participant