Skip to content

Commit

Permalink
transport: fixed a goroutine leak issue in tcp.go (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
wh-afra authored and lni committed Sep 25, 2023
1 parent d16220b commit a6b5353
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/transport/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,23 @@ func (t *TCP) Start() error {
panic(err)
}
var once sync.Once
connCloseCh := make(chan struct{})
closeFn := func() {
once.Do(func() {
select {
case connCloseCh <- struct{}{}:
default:
}
if err := conn.Close(); err != nil {
plog.Errorf("failed to close the connection %v", err)
}
})
}
t.connStopper.RunWorker(func() {
<-t.stopper.ShouldStop()
select {
case <-t.stopper.ShouldStop():
case <-connCloseCh:
}
closeFn()
})
t.connStopper.RunWorker(func() {
Expand Down

0 comments on commit a6b5353

Please sign in to comment.