Skip to content

Commit

Permalink
fix(ebpf): fix stderr reading deadlock (#1292)
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev committed Jul 22, 2022
1 parent 7d2424b commit c163b37
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pkg/agent/ebpfspy/session_linux.go
Expand Up @@ -100,19 +100,27 @@ func (s *session) Start() error {
func (s *session) Reset(cb func([]byte, uint64) error) error {
var errs error
s.cmd.Process.Signal(syscall.SIGINT)
stderr, err := io.ReadAll(s.stderr)
if err != nil {
errs = multierror.Append(errs, err)
}

if err := s.cmd.Wait(); err != nil {
errs = multierror.Append(errs, fmt.Errorf("%s: %w", stderr, err))
type stderrRes struct {
bs []byte
err error
}
stderrCh := make(chan stderrRes)
go func() {
bs, err := io.ReadAll(s.stderr)
stderrCh <- stderrRes{bs, err}
}()
for v := range s.ch {
if err := cb(v.name, uint64(v.val)); err != nil {
errs = multierror.Append(errs, err)
}
}
stderr := <-stderrCh
if stderr.err != nil {
errs = multierror.Append(errs, stderr.err)
}
if err := s.cmd.Wait(); err != nil {
errs = multierror.Append(errs, fmt.Errorf("%s: %w", string(stderr.bs), err))
}

s.stopMutex.Lock()
defer s.stopMutex.Unlock()
Expand Down

0 comments on commit c163b37

Please sign in to comment.