Skip to content

Commit

Permalink
avoid memory leak when reconnecting to a server
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Aug 23, 2022
1 parent ba2ceac commit b7cbaec
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
5 changes: 1 addition & 4 deletions endpointclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ func (t *endpointClient) run() {
for {
t.runInner()

timer := time.NewTimer(netReconnectPeriod)
defer timer.Stop()

select {
case <-timer.C:
case <-time.After(netReconnectPeriod):
case <-t.ctx.Done():
return
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/udplistener/udplistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,8 @@ func (c *conn) Read(byt []byte) (int, error) {
var ok bool

if !c.readDeadline.IsZero() {
readTimer := time.NewTimer(time.Until(c.readDeadline))
defer readTimer.Stop()

select {
case <-readTimer.C:
case <-time.After(time.Until(c.readDeadline)):
return 0, errTimeout
case buf, ok = <-c.read:
}
Expand Down

0 comments on commit b7cbaec

Please sign in to comment.