Skip to content

Commit

Permalink
Reopen the file stream if the read error is ESTALE.
Browse files Browse the repository at this point in the history
Issue #505
  • Loading branch information
jaqx0r committed May 7, 2021
1 parent 12162ff commit 23ff9be
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/tailer/logstream/filestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ package logstream
import (
"bytes"
"context"
"errors"
"expvar"
"io"
"os"
"sync"
"syscall"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -113,8 +115,20 @@ func (fs *fileStream) stream(ctx context.Context, wg *sync.WaitGroup, waker wake
}

if err != nil && err != io.EOF {
glog.Info(err)
logErrors.Add(fs.pathname, 1)
// TODO: This could be generalised to check for any retryable
// errors, and end on unretriables; e.g. ESTALE looks
// retryable.
var serr *os.SyscallError
if errors.As(err, &serr) && serr.Err == syscall.ESTALE {
glog.Infof("%v: reopening stream due to %s", fd, err)
if nerr := fs.stream(ctx, wg, waker, fi, true); nerr != nil {
glog.Info(nerr)
}
// Close this stream.
return
}
glog.Info(err)
}

// If we have read no bytes and are at EOF, check for truncation and rotation.
Expand Down

0 comments on commit 23ff9be

Please sign in to comment.