Skip to content

Commit

Permalink
fix(client): properly cancel contexts in proposal pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
d0tsh authored and mkaczanowski committed Nov 17, 2024
1 parent 6d78ead commit 50c99b9
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions internal/pkg/cosmos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,18 @@ func (cc *Client) GetLatestBlockHeight(ctx context.Context) (int64, error) {
}

func (cc *Client) GetProposalsV1(ctx context.Context) (v1.Proposals, error) {
key := []byte{}
var key []byte
proposals := make(v1.Proposals, 0, 50)

for {
var cancel context.CancelFunc

ctx, cancel = context.WithTimeout(ctx, cc.timeout)
defer cancel()

res, err := cc.v1Client.Proposals(ctx, &v1.QueryProposalsRequest{
pageCtx, cancel := context.WithTimeout(ctx, cc.timeout)
res, err := cc.v1Client.Proposals(pageCtx, &v1.QueryProposalsRequest{
Pagination: &query.PageRequest{
Key: key,
Limit: cc.paginationLimit,
},
}, cc.callOptions...)
cancel()
if err != nil {
return nil, errors.Wrapf(err, "failed to get proposals")
}
Expand All @@ -139,21 +136,18 @@ func (cc *Client) GetProposalsV1(ctx context.Context) (v1.Proposals, error) {
}

func (cc *Client) GetProposalsV1beta1(ctx context.Context) (v1beta1.Proposals, error) {
key := []byte{}
var key []byte
proposals := make(v1beta1.Proposals, 0, 50)

for {
var cancel context.CancelFunc

ctx, cancel = context.WithTimeout(ctx, cc.timeout)
defer cancel()

res, err := cc.v1beta1Client.Proposals(ctx, &v1beta1.QueryProposalsRequest{
pageCtx, cancel := context.WithTimeout(ctx, cc.timeout)
res, err := cc.v1beta1Client.Proposals(pageCtx, &v1beta1.QueryProposalsRequest{
Pagination: &query.PageRequest{
Key: key,
Limit: cc.paginationLimit,
},
}, cc.callOptions...)
cancel()
if err != nil {
return nil, errors.Wrapf(err, "failed to get proposals")
}
Expand Down

0 comments on commit 50c99b9

Please sign in to comment.