Skip to content

Commit aad8697

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

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 12 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,11 @@ 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+
// TODO(toru): find out why the file does not exists
122+
if errors.Is(err, fs.ErrNotExist) {
123+
return 0, nil
124+
}
125+
119126
return 0, xerrors.Errorf("cannot read memory.limit_in_bytes: %v", err)
120127
}
121128

@@ -134,6 +141,11 @@ func readLimit(memCgroupPath string) (uint64, error) {
134141
func readCache(memCgroupPath string) (uint64, error) {
135142
f, err := os.Open(filepath.Join(string(memCgroupPath), "memory.stat"))
136143
if err != nil {
144+
// TODO(toru): find out why the file does not exists
145+
if errors.Is(err, fs.ErrNotExist) {
146+
return 0, nil
147+
}
148+
137149
return 0, xerrors.Errorf("cannot read memory.stat: %w", err)
138150
}
139151
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)