Skip to content

Commit

Permalink
fix: add timeout for query ask
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Oct 8, 2023
1 parent ce9c52a commit 2876111
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/droplet-client/retrieval.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"errors"
"fmt"
"io"
"strings"
"time"

tm "github.com/buger/goterm"
"github.com/docker/go-units"
Expand Down Expand Up @@ -351,8 +353,14 @@ var clientQueryRetrievalAskCmd = &cli.Command{
defer closer()
ctx := cli2.ReqContext(cctx)

ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()

ask, err := api.ClientMinerQueryOffer(ctx, maddr, dataCid, nil)
if err != nil {
if strings.Contains(err.Error(), "context by cancel") {
return fmt.Errorf("timeout: %v", err)
}
return err
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/droplet-client/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ var storageAsksQueryCmd = &cli.Command{
defer closer()
ctx := cli2.ReqContext(cctx)

ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()

var pid peer.ID
if pidstr := cctx.String("peerid"); pidstr != "" {
p, err := peer.Decode(pidstr)
Expand All @@ -287,6 +290,9 @@ var storageAsksQueryCmd = &cli.Command{

ask, err := api.ClientQueryAsk(ctx, pid, maddr)
if err != nil {
if strings.Contains(err.Error(), "context by cancel") {
return fmt.Errorf("timeout: %v", err)
}
return err
}

Expand Down

0 comments on commit 2876111

Please sign in to comment.