Skip to content

Commit 8971e30

Browse files
committed
[ws-daemon] Improve cache error handling
1 parent 3f05d6f commit 8971e30

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

components/ws-daemon/pkg/daemon/cache_reclaim.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package daemon
77
import (
88
"bufio"
99
"context"
10+
"errors"
11+
"io/fs"
1012
"io/ioutil"
1113
"math"
1214
"os"
@@ -116,6 +118,10 @@ func readLimit(memCgroupPath string) (uint64, error) {
116118
fn := filepath.Join(string(memCgroupPath), "memory.limit_in_bytes")
117119
fc, err := os.ReadFile(fn)
118120
if err != nil {
121+
if errors.Is(err, fs.ErrNotExist) {
122+
return 0, nil
123+
}
124+
119125
return 0, xerrors.Errorf("cannot read memory.limit_in_bytes: %v", err)
120126
}
121127

@@ -134,6 +140,10 @@ func readLimit(memCgroupPath string) (uint64, error) {
134140
func readCache(memCgroupPath string) (uint64, error) {
135141
f, err := os.Open(filepath.Join(string(memCgroupPath), "memory.stat"))
136142
if err != nil {
143+
if errors.Is(err, fs.ErrNotExist) {
144+
return 0, nil
145+
}
146+
137147
return 0, xerrors.Errorf("cannot read memory.stat: %w", err)
138148
}
139149
defer f.Close()

components/ws-daemon/pkg/daemon/cache_reclaim_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func TestReadLimitBadValue(t *testing.T) {
5454
t.Fatal(err)
5555
}
5656
_, err = readCache(tempdir)
57-
if err == nil {
58-
t.Fatal("expected failure")
57+
if err != nil {
58+
t.Fatalf("unexpected error: is '%v' but expected no error", err)
5959
}
6060
}
6161
}

0 commit comments

Comments
 (0)