Skip to content

Commit 2a3ff2a

Browse files
committed
handle readahead 403 errors
this usually shouldn't happen because the original read request should have failed first before we trigger readahead, but eventual consistency or IAM changes can cause readahead range GET to fail fixes #243
1 parent 3691b6b commit 2a3ff2a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

internal/buffer_pool.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ func (b *Buffer) Read(p []byte) (n int, err error) {
375375
for b.reader == nil && b.err == nil {
376376
bufferLog.Debugf("waiting for stream")
377377
b.cond.Wait()
378+
if b.err != nil {
379+
err = b.err
380+
return
381+
}
378382
}
379383

380384
if b.buf != nil {

internal/goofys_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,3 +1927,27 @@ func (s *GoofysTest) TestRenameOverwrite(t *C) {
19271927
err = os.Rename(file, rename)
19281928
t.Assert(err, IsNil)
19291929
}
1930+
1931+
func (s *GoofysTest) TestRead403(t *C) {
1932+
s.fs.flags.StatCacheTTL = 1 * time.Minute
1933+
s.fs.flags.TypeCacheTTL = 1 * time.Minute
1934+
1935+
// cache the inode first so we don't get 403 when we lookup
1936+
in, err := s.LookUpInode(t, "file1")
1937+
t.Assert(err, IsNil)
1938+
1939+
fh, err := in.OpenFile()
1940+
t.Assert(err, IsNil)
1941+
1942+
s.fs.awsConfig.Credentials = credentials.AnonymousCredentials
1943+
s.fs.sess = session.New(s.fs.awsConfig)
1944+
s.fs.s3 = s.fs.newS3()
1945+
1946+
// fake enable read-ahead
1947+
fh.seqReadAmount = uint64(READAHEAD_CHUNK)
1948+
1949+
buf := make([]byte, 5)
1950+
1951+
_, err = fh.ReadFile(0, buf)
1952+
t.Assert(err, Equals, syscall.EACCES)
1953+
}

0 commit comments

Comments
 (0)