From b338ad35897117e38ad9a72dfe5cce5d0d05d6ba Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 8 Mar 2026 09:26:57 +0200 Subject: task: harden truncate signal lifecycle in processor readers (task 372) --- internal/io/fs/readfile_processor.go | 8 +++++--- internal/io/fs/readfile_processor_optimized.go | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/io/fs/readfile_processor.go b/internal/io/fs/readfile_processor.go index 1658541..4e636a4 100644 --- a/internal/io/fs/readfile_processor.go +++ b/internal/io/fs/readfile_processor.go @@ -29,10 +29,12 @@ func (f *readFile) StartWithProcessor(ctx context.Context, ltx lcontext.LContext return err } + truncateCtx, cancelTruncate := context.WithCancel(ctx) + defer cancelTruncate() + truncate := make(chan struct{}) - defer close(truncate) - go f.periodicTruncateCheck(ctx, truncate) + go f.periodicTruncateCheck(truncateCtx, truncate) // Process file with direct callbacks instead of channels err = f.readWithProcessor(ctx, fd, reader, truncate, ltx, processor, re) @@ -283,4 +285,4 @@ func (fp *filteringProcessor) processWithContext(rawLine *bytes.Buffer, lineNum } return nil -} \ No newline at end of file +} diff --git a/internal/io/fs/readfile_processor_optimized.go b/internal/io/fs/readfile_processor_optimized.go index 716fb1f..96d5a16 100644 --- a/internal/io/fs/readfile_processor_optimized.go +++ b/internal/io/fs/readfile_processor_optimized.go @@ -226,7 +226,6 @@ func (f *readFile) StartWithProcessorOptimized(ctx context.Context, ltx lcontext defer cancelTruncate() truncate := make(chan struct{}) - defer close(truncate) go f.periodicTruncateCheck(truncateCtx, truncate) @@ -368,4 +367,4 @@ func (f *readFile) tailWithProcessorOptimized(ctx context.Context, fd *os.File, default: } } -} \ No newline at end of file +} -- cgit v1.2.3