Skip to content

Commit

Permalink
[pkg/stanza] Stop readerFactory from returning an error when creating…
Browse files Browse the repository at this point in the history
… an unsafeReader (open-telemetry#12767)

Because the unsafeReader is not linked to any file, it caused an error when the readerBuilder tried to set its offset to the end of the file. Because the unsafeReader is later initialized with other data, we can simply ignore setting the offset here, because it will be overwritten anyway.
  • Loading branch information
aboguszewski-sumo committed Jul 28, 2022
1 parent aa86130 commit 5933316
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/stanza/fileconsumer/reader_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (f *readerFactory) copy(old *Reader, newFile *os.File) (*Reader, error) {
}

func (f *readerFactory) unsafeReader() (*Reader, error) {
return f.newReaderBuilder().build()
return f.newReaderBuilder().Unsafe().build()
}

func (f *readerFactory) newFingerprint(file *os.File) (*Fingerprint, error) {
Expand All @@ -60,6 +60,7 @@ type readerBuilder struct {
fp *Fingerprint
offset int64
splitter *helper.Splitter
isUnsafe bool
}

func (f *readerFactory) newReaderBuilder() *readerBuilder {
Expand All @@ -86,6 +87,11 @@ func (b *readerBuilder) withOffset(offset int64) *readerBuilder {
return b
}

func (b *readerBuilder) Unsafe() *readerBuilder {
b.isUnsafe = true
return b
}

func (b *readerBuilder) build() (r *Reader, err error) {
r = &Reader{
readerConfig: b.readerConfig,
Expand Down Expand Up @@ -122,7 +128,8 @@ func (b *readerBuilder) build() (r *Reader, err error) {
r.Fingerprint = fp
}

if !b.fromBeginning {
// unsafeReader has the file set to nil, so don't try emending its offset.
if !b.fromBeginning && !b.isUnsafe {
if err := r.offsetToEnd(); err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
change_type: bug_fix

component: pkg/stanza

note: Stop readerFactory from returning an error when creating an unsafeReader

issues: [12766]

subtext: This bug caused the filelog receiver to crash when the collector was restarted and the logs were being read from the end of the file

0 comments on commit 5933316

Please sign in to comment.