Skip to content

Commit

Permalink
handle readahead 403 errors
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kahing committed Oct 25, 2017
1 parent 3691b6b commit 2a3ff2a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/buffer_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ func (b *Buffer) Read(p []byte) (n int, err error) {
for b.reader == nil && b.err == nil {
bufferLog.Debugf("waiting for stream")
b.cond.Wait()
if b.err != nil {
err = b.err
return
}
}

if b.buf != nil {
Expand Down
24 changes: 24 additions & 0 deletions internal/goofys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1927,3 +1927,27 @@ func (s *GoofysTest) TestRenameOverwrite(t *C) {
err = os.Rename(file, rename)
t.Assert(err, IsNil)
}

func (s *GoofysTest) TestRead403(t *C) {
s.fs.flags.StatCacheTTL = 1 * time.Minute
s.fs.flags.TypeCacheTTL = 1 * time.Minute

// cache the inode first so we don't get 403 when we lookup
in, err := s.LookUpInode(t, "file1")
t.Assert(err, IsNil)

fh, err := in.OpenFile()
t.Assert(err, IsNil)

s.fs.awsConfig.Credentials = credentials.AnonymousCredentials
s.fs.sess = session.New(s.fs.awsConfig)
s.fs.s3 = s.fs.newS3()

// fake enable read-ahead
fh.seqReadAmount = uint64(READAHEAD_CHUNK)

buf := make([]byte, 5)

_, err = fh.ReadFile(0, buf)
t.Assert(err, Equals, syscall.EACCES)
}

0 comments on commit 2a3ff2a

Please sign in to comment.