From d95b2597773cc3678cb1594d960df8c4203b811f Mon Sep 17 00:00:00 2001 From: Michal Iskierko Date: Fri, 30 Dec 2022 21:09:42 +0100 Subject: [PATCH] fix: add 5 seconds timeout context when installing stickers --- services/stickers/api.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/stickers/api.go b/services/stickers/api.go index db879d167..47e88d68f 100644 --- a/services/stickers/api.go +++ b/services/stickers/api.go @@ -3,6 +3,7 @@ package stickers import ( "context" "math/big" + "time" "github.com/zenthangplus/goccm" "olympos.io/encoding/edn" @@ -24,6 +25,7 @@ import ( ) const maxConcurrentRequests = 3 +const requestTimeout = time.Duration(5) * time.Second // ConnectionType constants type stickerStatus int @@ -297,8 +299,11 @@ func (api *API) fetchStickerPacks(chainID uint64, resultChan chan<- *StickerPack } func (api *API) fetchPackData(stickerType *stickers.StickerType, packID *big.Int, translateHashes bool) (*StickerPack, error) { - callOpts := &bind.CallOpts{Context: api.ctx, Pending: false} + timeoutContext, timeoutCancel := context.WithTimeout(api.ctx, requestTimeout) + defer timeoutCancel() + + callOpts := &bind.CallOpts{Context: timeoutContext, Pending: false} packData, err := stickerType.GetPackData(callOpts, packID) if err != nil { return nil, err