Skip to content

Commit

Permalink
bugfix: <-timer.C after Stop will hang if timer.C is empty (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie authored Mar 17, 2024
1 parent 6cf311a commit a4a3d96
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,7 @@ func New(config Config) *Client {
// the event can't be sent within 30s.
func (c *Client) receive(e *Event) {
t := time.NewTimer(30 * time.Second)
defer func() {
if !t.Stop() {
<-t.C
}
}()
defer t.Stop()

select {
case c.rx <- e:
Expand Down
6 changes: 1 addition & 5 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,7 @@ func (c *Client) write(event *Event) {
}

t := time.NewTimer(30 * time.Second)
defer func() {
if !t.Stop() {
<-t.C
}
}()
defer t.Stop()

select {
case c.tx <- event:
Expand Down

0 comments on commit a4a3d96

Please sign in to comment.