add RPC timeout to maybeSchedRequest

This commit is contained in:
Howard Yeh 2020-06-23 17:42:47 +08:00
parent d9de9b7cb4
commit be4112ee68

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"sort" "sort"
"sync" "sync"
"time"
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -214,7 +215,10 @@ func (sh *scheduler) maybeSchedRequest(req *workerRequest) (bool, error) {
needRes := ResourceTable[req.taskType][sh.spt] needRes := ResourceTable[req.taskType][sh.spt]
for wid, worker := range sh.workers { for wid, worker := range sh.workers {
ok, err := req.sel.Ok(req.ctx, req.taskType, sh.spt, worker) rpcCtx, cancel := context.WithTimeout(req.ctx, 5*time.Second)
ok, err := req.sel.Ok(rpcCtx, req.taskType, sh.spt, worker)
cancel()
if err != nil { if err != nil {
return false, err return false, err
} }