Skip to content

Commit

Permalink
Recover from panic
Browse files Browse the repository at this point in the history
closes #8
  • Loading branch information
corny committed Sep 18, 2018
1 parent 4bc79c3 commit db6c46a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion request.go
Expand Up @@ -43,7 +43,7 @@ func (req *simpleRequest) handleReply(err error, _ net.IP, tRecv *time.Time) {
if err == nil && tRecv != nil && req.tFinish == nil {
req.tFinish = tRecv
}
close(req.wait)
req.close()
}

func (req *simpleRequest) init() {
Expand All @@ -52,6 +52,12 @@ func (req *simpleRequest) init() {
}

func (req *simpleRequest) close() {
defer func() {
// Double-closing is very unlikely, but a race condition may
// happen when sending fails and a reply is received anyway.
recover()
}()

close(req.wait)
}

Expand Down

0 comments on commit db6c46a

Please sign in to comment.