Skip to content

Commit e8116e6

Browse files
authored
[chore][pkg/stanza]: when found duplicate, continue from outer loop (#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
1 parent b716a4d commit e8116e6

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

pkg/stanza/fileconsumer/file.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func (m *Manager) makeFingerprint(path string) (*fingerprint.Fingerprint, *os.Fi
209209
// been read this polling interval
210210
func (m *Manager) makeReaders(paths []string) []*reader.Reader {
211211
readers := make([]*reader.Reader, 0, len(paths))
212+
OUTER:
212213
for _, path := range paths {
213214
fp, file := m.makeFingerprint(path)
214215
if fp == nil {
@@ -222,7 +223,7 @@ func (m *Manager) makeReaders(paths []string) []*reader.Reader {
222223
if err := file.Close(); err != nil {
223224
m.Debugw("problem closing file", zap.Error(err))
224225
}
225-
continue
226+
continue OUTER
226227
}
227228
}
228229

pkg/stanza/fileconsumer/file_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,7 @@ func TestStalePartialFingerprintDiscarded(t *testing.T) {
16621662
waitForToken(t, emitCalls, []byte(content))
16631663
expectNoTokens(t, emitCalls)
16641664
operator.wg.Wait()
1665+
require.Len(t, operator.previousPollFiles, 1)
16651666

16661667
// keep append data to file1 and file2
16671668
newContent := "bbbbbbbbbbbb"

0 commit comments

Comments
 (0)