fix: client unexpected timeout (#1239)

* fix: client unexpected timeout

Signed-off-by: Jim Ma <majinjing3@gmail.com>
This commit is contained in:
Jim Ma 2022-04-11 18:17:29 +08:00 committed by Gaius
parent 3ccf3ae929
commit 1f79e76a4b
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
1 changed files with 3 additions and 14 deletions

View File

@ -45,9 +45,10 @@ import (
) )
const ( const (
// TODO implement peer task health check
// reasonContextCanceled = "context canceled" // reasonContextCanceled = "context canceled"
// reasonReScheduleTimeout = "wait more available peers from scheduler timeout"
reasonScheduleTimeout = "wait first peer packet from scheduler timeout" reasonScheduleTimeout = "wait first peer packet from scheduler timeout"
reasonReScheduleTimeout = "wait more available peers from scheduler timeout"
reasonPeerGoneFromScheduler = "scheduler says client should disconnect" reasonPeerGoneFromScheduler = "scheduler says client should disconnect"
reasonBackSourceDisabled = "download from source disabled" reasonBackSourceDisabled = "download from source disabled"
@ -925,18 +926,6 @@ func (pt *peerTaskConductor) waitAvailablePeerPacket() (int32, bool) {
pt.span.AddEvent("back source due to scheduler says need back source ") pt.span.AddEvent("back source due to scheduler says need back source ")
// TODO optimize back source when already downloaded some pieces // TODO optimize back source when already downloaded some pieces
pt.backSource() pt.backSource()
case <-time.After(pt.schedulerOption.ScheduleTimeout.Duration):
if pt.schedulerOption.DisableAutoBackSource {
pt.cancel(base.Code_ClientScheduleTimeout, reasonBackSourceDisabled)
err := fmt.Errorf("%s, auto back source disabled", pt.failedReason)
pt.span.RecordError(err)
pt.Errorf(err.Error())
} else {
pt.Warnf("start download from source due to %s", reasonReScheduleTimeout)
pt.span.AddEvent("back source due to schedule timeout")
pt.needBackSource.Store(true)
pt.backSource()
}
} }
return -1, false return -1, false
} }