Skip to content

Commit

Permalink
Merge pull request #55 from celenium-io/fix/request-timeout
Browse files Browse the repository at this point in the history
Fix: add request timeout
  • Loading branch information
aopoltorzhicky committed Nov 25, 2023
2 parents 9672695 + 7860501 commit 770ff52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/indexer/receiver/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ func (r *Module) worker(ctx context.Context, level types.Level) {
default:
}

block, err := r.api.BlockDataGet(ctx, level)
requestTimeout, cancel := context.WithTimeout(ctx, time.Second*10)
block, err := r.api.BlockDataGet(requestTimeout, level)
if err != nil {
cancel()

if errors.Is(err, context.Canceled) {
return
}

r.Log.Err(err).
Uint64("height", uint64(level)).
Msg("while getting block data")
Expand All @@ -38,6 +42,7 @@ func (r *Module) worker(ctx context.Context, level types.Level) {
}

result = block
cancel()
break
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/node/rpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
"golang.org/x/time/rate"
)

const (
celeniumUserAgent = "Celenium Indexer"
)

type API struct {
client *http.Client
cfg config.DataSource
Expand Down Expand Up @@ -80,6 +84,7 @@ func (api *API) get(ctx context.Context, path string, args map[string]string, ou
if err != nil {
return err
}
req.Header.Set("User-Agent", celeniumUserAgent)

response, err := api.client.Do(req)
if err != nil {
Expand Down Expand Up @@ -123,6 +128,7 @@ func (api *API) post(ctx context.Context, requests []types.Request, output any)
if err != nil {
return err
}
req.Header.Set("User-Agent", celeniumUserAgent)

response, err := api.client.Do(req)
if err != nil {
Expand Down

0 comments on commit 770ff52

Please sign in to comment.