Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions cmd_vfs_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,45 @@ var vfsRawCmd = &cli.Command{
r = f
}

return jsonParseThenAppend(r, func(e *vfsEvent) error {
return appender.AppendRow(e.Timestamp, e.Probe, e.Tid, e.ReturnValue,
e.Path, e.Inode, e.Offset, e.Length)
events := make(chan *vfsEvent, 1024)
writeErrCh := make(chan error, 1)
done := make(chan struct{})

go func() {
defer close(done)
for e := range events {
if err := appender.AppendRow(e.Timestamp, e.Probe, e.Tid, e.ReturnValue,
e.Path, e.Inode, e.Offset, e.Length); err != nil {
writeErrCh <- err
return
}
}
}()

parseErr := jsonParseThenAppend(r, func(e *vfsEvent) error {
select {
case events <- e:
return nil
case err := <-writeErrCh:
Comment on lines +318 to +322

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop parsing immediately when writer errors

The select can still choose events <- e even when writeErrCh is already readable, because Go selects randomly among ready cases. If the writer goroutine fails, the parser may enqueue up to the remaining buffer capacity (1024) of additional events before it eventually notices the error, and those events will be dropped because the writer has exited. That creates silent data loss in the exact scenario the error reporting is meant to handle. Consider prioritizing the error path (e.g., non-blocking check of writeErrCh before enqueue) so parsing halts as soon as the writer fails.

Useful? React with 👍 / 👎.

if err != nil {
return err
}
return errors.New("writer stopped")
}
})

close(events)
<-done

if parseErr != nil {
return parseErr
}

select {
case err := <-writeErrCh:
return err
default:
return nil
}
},
}
Loading