Skip to content

Commit

Permalink
[chore][pkg/stanza]: when found duplicate, continue from outer loop (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#28889)

**Description:** 
Fix a bug when duplicate readers are added to the active list even after
the underlying file is closed. To fix this, continue from the outer
loop.
This doesn't result in any duplicates, but this will keep producing the
following annoying error every time.
```2023-11-05T02:34:03.530+0530       ERROR       Failed to seek  {"component": "fileconsumer", "path": "/var/folders/fs/njj5c3xx7vdcsr28n19vykw00000gn/T/TestStalePartialFingerprintDiscarded2443925830/001/1616317274.log2", "error": "seek /var/folders/fs/njj5c3xx7vdcsr28n19vykw00000gn/T/TestStalePartialFingerprintDiscarded2443925830/001/1616317274.log2: file already closed"}```

**Testing:** Update the test to check the previouPollFiles
  • Loading branch information
VihasMakwana authored and RoryCrispin committed Nov 24, 2023
1 parent d11d7c7 commit 45b3c3d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/stanza/fileconsumer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func (m *Manager) makeFingerprint(path string) (*fingerprint.Fingerprint, *os.Fi
// been read this polling interval
func (m *Manager) makeReaders(paths []string) []*reader.Reader {
readers := make([]*reader.Reader, 0, len(paths))
OUTER:
for _, path := range paths {
fp, file := m.makeFingerprint(path)
if fp == nil {
Expand All @@ -222,7 +223,7 @@ func (m *Manager) makeReaders(paths []string) []*reader.Reader {
if err := file.Close(); err != nil {
m.Debugw("problem closing file", zap.Error(err))
}
continue
continue OUTER
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/stanza/fileconsumer/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,7 @@ func TestStalePartialFingerprintDiscarded(t *testing.T) {
waitForToken(t, emitCalls, []byte(content))
expectNoTokens(t, emitCalls)
operator.wg.Wait()
require.Len(t, operator.previousPollFiles, 1)

// keep append data to file1 and file2
newContent := "bbbbbbbbbbbb"
Expand Down

0 comments on commit 45b3c3d

Please sign in to comment.