Skip to content

Commit

Permalink
feat(http): Use the same http timeout for both clients
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Aug 31, 2022
1 parent 97867ae commit c0a3881
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 1 addition & 6 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"io"
"net/http"
"net/url"
"time"

"github.com/samcm/beacon/api/types"
"github.com/sirupsen/logrus"
Expand All @@ -29,11 +28,7 @@ type consensusClient struct {
}

// NewConsensusClient creates a new ConsensusClient.
func NewConsensusClient(ctx context.Context, log logrus.FieldLogger, url string) ConsensusClient {
client := http.Client{
Timeout: time.Second * 10,
}

func NewConsensusClient(ctx context.Context, log logrus.FieldLogger, url string, client http.Client) ConsensusClient {
return &consensusClient{
url: url,
log: log,
Expand Down
20 changes: 14 additions & 6 deletions bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package beacon

import (
"context"
"net/http"
"time"

eth2client "github.com/attestantio/go-eth2-client"
"github.com/attestantio/go-eth2-client/http"
ehttp "github.com/attestantio/go-eth2-client/http"
"github.com/rs/zerolog"
"github.com/samcm/beacon/api"
)
Expand All @@ -25,10 +26,12 @@ func (n *node) ensureClients(ctx context.Context) error {
case <-ctx.Done():
return ctx.Err()
default:
client, err := http.New(ctx,
http.WithAddress(n.config.Addr),
http.WithLogLevel(zerolog.Disabled),
http.WithTimeout(90*time.Second),
timeout := 90 * time.Second

client, err := ehttp.New(ctx,
ehttp.WithAddress(n.config.Addr),
ehttp.WithLogLevel(zerolog.Disabled),
ehttp.WithTimeout(timeout),
)
if err != nil {
failures++
Expand All @@ -48,7 +51,12 @@ func (n *node) ensureClients(ctx context.Context) error {
}

n.client = client
n.api = api.NewConsensusClient(ctx, n.log, n.config.Addr)

httpClient := http.Client{
Timeout: timeout,
}

n.api = api.NewConsensusClient(ctx, n.log, n.config.Addr, httpClient)

break
}
Expand Down

0 comments on commit c0a3881

Please sign in to comment.