Skip to content

Commit

Permalink
optimize retry strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Aug 27, 2016
1 parent 94f61b5 commit b4e5181
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,23 @@ func main() {
}
checkError(err)
idx := rr % numconn
mux := muxes[idx]
p2, err := mux.session.Open()
if err != nil { // yamux failure
log.Println(err)
p1.Close()

OPEN_P2:
// do auto expiration
if autoexpire > 0 && time.Now().After(muxes[idx].ttl) {
log.Println("autoexpired")
muxes[idx].session = createConn()
muxes[idx].ttl = time.Now().Add(time.Duration(autoexpire) * time.Second)
continue
}
if autoexpire > 0 && time.Now().After(muxes[idx].ttl) { // auto expiration
log.Println("autoexpired")

// do session open
p2, err := muxes[idx].session.Open()
if err != nil { // yamux failure
log.Println(err)
p1.Close()
muxes[idx].session = createConn()
muxes[idx].ttl = time.Now().Add(time.Duration(autoexpire) * time.Second)
goto OPEN_P2
}
go handleClient(p1, p2)
rr++
Expand Down

0 comments on commit b4e5181

Please sign in to comment.