From 4fec65d949f4778c545f1457b4ae1306f318a724 Mon Sep 17 00:00:00 2001 From: yi111 <153097222+Yi-111-a@users.noreply.github.com> Date: Mon, 28 Sep 2026 14:35:41 +0800 Subject: [PATCH] filer: demote client-cancelled directory listing log from error (#11495) (#11496) * filer: demote client-cancelled directory listing log from error (#11495) * filer: quote path in canceled listing log --------- Co-authored-by: Chris Lu --- weed/filer/filer.go | 2 +- weed/filer/filer_prefix_object_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/weed/filer/filer.go b/weed/filer/filer.go index 88943d4c0..d83486c86 100644 --- a/weed/filer/filer.go +++ b/weed/filer/filer.go @@ -606,7 +606,7 @@ func (f *Filer) doListDirectoryEntries(ctx context.Context, p util.FullPath, sta lastFileName, err = f.Store.ListDirectoryPrefixedEntries(ctx, p, startFileName, inclusive, limit, prefix, func(entry *Entry) (bool, error) { select { case <-ctx.Done(): - glog.Errorf("Context is done.") + glog.V(1).InfofCtx(ctx, "listing %q canceled: %v", p, ctx.Err()) return false, fmt.Errorf("context canceled: %w", ctx.Err()) default: if entry.TtlSec > 0 && !entry.IsDirectory() { diff --git a/weed/filer/filer_prefix_object_test.go b/weed/filer/filer_prefix_object_test.go index b18b9d6ba..42f9ba480 100644 --- a/weed/filer/filer_prefix_object_test.go +++ b/weed/filer/filer_prefix_object_test.go @@ -104,3 +104,23 @@ func TestExpiredFileIsDeletedOnRead(t *testing.T) { require.ErrorIs(t, err, filer_pb.ErrNotFound, "native TTL lookup should remove the expired metadata row") } + +func TestListDirectoryEntriesContextCanceled(t *testing.T) { + f, store := newTestFilerWithStubStore() + ctx := context.Background() + + require.NoError(t, store.InsertEntry(ctx, &Entry{ + FullPath: util.FullPath("/dir/file1.txt"), + Attr: Attr{Mode: 0o644}, + })) + + canceledCtx, cancel := context.WithCancel(ctx) + cancel() + + _, _, err := f.doListDirectoryEntries(canceledCtx, util.FullPath("/dir"), "", false, 10, "", func(entry *Entry) (bool, error) { + return true, nil + }) + require.Error(t, err) + assert.ErrorContains(t, err, "context canceled") +} +