Skip to content

Commit

Permalink
fix fault recovery issue
Browse files Browse the repository at this point in the history
  • Loading branch information
GheisMohammadi committed Aug 22, 2023
1 parent 78d71da commit 1ae0bd0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions p2p/stream/types/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,14 @@ func (st *BaseStream) FailedTimes() int {
}

func (st *BaseStream) AddFailedTimes(faultRecoveryThreshold time.Duration) {
durationSinceLastFailure := time.Now().Sub(st.lastFailureTime)
if durationSinceLastFailure >= faultRecoveryThreshold {
st.ResetFailedTimes()
if st.failedTimes > 0 {
durationSinceLastFailure := time.Now().Sub(st.lastFailureTime)
if durationSinceLastFailure >= faultRecoveryThreshold {
st.ResetFailedTimes()
}
}
st.failedTimes++
st.lastFailureTime = time.Now()
}

func (st *BaseStream) ResetFailedTimes() {
Expand Down

0 comments on commit 1ae0bd0

Please sign in to comment.