Skip to content

fix(dir): report an error instead of panicking when the path is missing - #1660

Merged
LinkinStars merged 1 commit into
apache:devfrom
NUAAwqy:fix/dir-dirsize-panics-on-missing-path
Nov 3, 2026
Merged

LinkinStars merged 1 commit into
apache:devfrom
NUAAwqy:fix/dir-dirsize-panics-on-missing-path

Conversation

@NUAAwqy

@NUAAwqy NUAAwqy commented Oct 30, 2026

Copy link
Copy Markdown

Fixes #

Proposed Changes

  • pkg/dir.DirSize now checks the error its filepath.Walk callback is given before it uses the FileInfo. filepath.Walk passes a nil info when the root cannot be stat-ed, so a missing path used to raise invalid memory address or nil pointer dereference instead of returning the error.
  • The admin dashboard's calculateStorage (internal/service/dashboard/dashboard_service.go:334) already logs and swallows an error from DirSize; with the panic that branch was unreachable, so a missing or unmounted upload directory turned the dashboard into a crash rather than an empty size.
  • Adds pkg/dir/dir_test.go: the happy path plus three missing-path cases that must return an error and must not panic.

Additional Info

Reproducer on main (6744295): dir.DirSize("/no/such/dir") panics with SIGSEGV at
pkg/dir/dir.go:45. After the change it returns the lstat …: no such file or directory
error. No new dependency; golangci-lint v2.6.2 (make lint) and go mod tidy are clean.

DirSize ignores the error its filepath.Walk callback is handed. When the
root cannot be stat-ed, filepath.Walk calls the callback with a nil
FileInfo, so info.IsDir() dereferences nil and the process panics.

This is reachable from the admin dashboard: calculateStorage walks
serviceConfig.UploadPath and explicitly logs and swallows the error it
expects back, so a missing or unmounted upload directory turns the
request into a panic instead of the intended "size unknown" path.

Handle the callback error before touching info.
@LinkinStars
LinkinStars changed the base branch from main to dev November 3, 2026 08:52
@LinkinStars LinkinStars self-assigned this Nov 3, 2026
@LinkinStars
LinkinStars merged commit e23d094 into apache:dev Nov 3, 2026
@LinkinStars

Copy link
Copy Markdown
Member

Reviewed and ran go test ./pkg/dir on 73576ca; the tests pass. The change handles missing paths correctly. Thanks for the fix!

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.

2 participants