Skip to content

Commit d298dfe

Browse files
PR #4803: fix(analyze): split input channel
Avoid deadlocks by writing first into a from file channel buffer, then into the engine. commit d71aff0 (main), cherry-pick
1 parent 0b98556 commit d298dfe

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pkg/analyze/analyze.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func Analyze(cfg Config) {
6464

6565
engineOutput := make(chan *detect.Finding)
6666
engineInput := make(chan protocol.Event)
67+
fromFile := make(chan protocol.Event)
6768

6869
source := engine.EventSources{Tracee: engineInput}
6970
sigEngine, err := engine.NewEngine(engineConfig, source, engineOutput)
@@ -87,13 +88,18 @@ func Analyze(cfg Config) {
8788
}
8889

8990
// producer
90-
go produce(fileReadCtx, stop, cfg.Source, engineInput)
91+
go produce(fileReadCtx, stop, cfg.Source, fromFile)
9192

9293
cfg.Printer.Preamble()
9394
defer cfg.Printer.Close()
9495
// consumer
9596
for {
9697
select {
98+
case event, ok := <-fromFile:
99+
if !ok {
100+
return
101+
}
102+
engineInput <- event
97103
case finding, ok := <-engineOutput:
98104
if !ok {
99105
return
@@ -112,6 +118,11 @@ drain:
112118
defer close(engineInput)
113119
for {
114120
select {
121+
case event, ok := <-fromFile:
122+
if !ok {
123+
return
124+
}
125+
engineInput <- event
115126
case finding, ok := <-engineOutput:
116127
if !ok {
117128
return

0 commit comments

Comments
 (0)