Skip to content

Commit

Permalink
cmd: fix process leak after timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyang89 committed Dec 19, 2023
1 parent c049108 commit e839816
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tcpmon/collector/nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func (m *NicCollector) doCollect(now time.Time) (*gproto.NicMetric, error) {

select {
case <-ctx.Done():
return nil, errors.Wrap(ctx.Err(), "ifconfig timeout")
err := c.Stop()
return nil, errors.Wrap(errors.CombineErrors(ctx.Err(), err), "ifconfig timeout")
case st := <-c.Start():
var nics gproto.NicMetric
nics.Type = gproto.MetricType_NIC
Expand Down
3 changes: 2 additions & 1 deletion tcpmon/collector/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func (m *SocketCollector) doCollect(now time.Time) (*gproto.TcpMetric, error) {

select {
case <-ctx.Done():
return nil, errors.Wrap(ctx.Err(), "ss timeout")
err := c.Stop()
return nil, errors.Wrap(errors.CombineErrors(ctx.Err(), err), "ss timeout")

case st := <-c.Start():
var t gproto.TcpMetric
Expand Down

0 comments on commit e839816

Please sign in to comment.