Skip to content

Commit

Permalink
fix: PeekNextResponse() block the goroutine (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianchen0119 authored Dec 28, 2023
1 parent 055371c commit a476bfd
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions pkg/pfcpsim/pfcpsim.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,18 @@ func (c *PFCPClient) PeekNextHeartbeatResponse() (*message.HeartbeatResponse, er
func (c *PFCPClient) PeekNextResponse() (message.Message, error) {
var resMsg message.Message

var err error

delay := time.NewTimer(c.responseTimeout)

for {
select {
case msg := <-c.recvChan:
case resMsg = <-c.recvChan:
if !delay.Stop() {
<-delay.C
}

resMsg = msg
return resMsg, nil
case <-delay.C:
if resMsg == nil {
err = NewTimeoutExpiredError()
}

return resMsg, err
return resMsg, NewTimeoutExpiredError()
}
}
}
Expand Down

0 comments on commit a476bfd

Please sign in to comment.