Skip to content

Commit

Permalink
Raise client timeout to 30s (#69)
Browse files Browse the repository at this point in the history
* rpc: create a client with a 30 second timeout

* cmd: pass the transport instead of http client to rpc.New
  • Loading branch information
patrislav authored Sep 4, 2024
1 parent d260064 commit 3babf64
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
17 changes: 7 additions & 10 deletions cmd/waas-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,14 @@ func main() {
}
}

// HTTP client to use for all outgoing connections out of the enclave
client := &http.Client{
Timeout: 10 * time.Second,
Transport: transport.Chain(
baseTransport,
transport.SetHeader("User-Agent", "waas-authenticator/"+waasauthenticator.VERSION),
traceid.Transport,
),
}
// HTTP transport chain to use for all outgoing connections out of the enclave
transportChain := transport.Chain(
baseTransport,
transport.SetHeader("User-Agent", "waas-authenticator/"+waasauthenticator.VERSION),
traceid.Transport,
)

s, err := rpc.New(cfg, client)
s, err := rpc.New(cfg, transportChain)
if err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions rpc/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,14 +341,14 @@ func TestStytchAuth(t *testing.T) {
stytchServer, tok := issueAccessTokenAndRunStytchJwksServer(t, "project-123", tokBuilderFn)
defer stytchServer.Close()

svc := initRPCWithClient(t, &http.Client{Transport: testTransport{
svc := initRPCWithClient(t, testTransport{
RoundTripper: http.DefaultTransport,
modifyRequest: func(req *http.Request) {
if strings.Contains(req.URL.String(), "stytch.com") {
req.URL.Host = stytchServer.Listener.Addr().String()
}
},
}})
})
tenant, _ := newTenantWithAuthConfig(t, svc.Enclave, proto.AuthConfig{
Stytch: proto.AuthStytchConfig{
Enabled: true,
Expand Down Expand Up @@ -442,14 +442,14 @@ func TestPlayFabAuth(t *testing.T) {
playfabAPI := httptest.NewServer(http.HandlerFunc(testCase.playfabHandler))
defer playfabAPI.Close()

svc := initRPCWithClient(t, &http.Client{Transport: testTransport{
svc := initRPCWithClient(t, testTransport{
RoundTripper: http.DefaultTransport,
modifyRequest: func(req *http.Request) {
if strings.Contains(req.URL.String(), "playfabapi.com") {
req.URL.Host = playfabAPI.Listener.Addr().String()
}
},
}})
})
tenant, _ := newTenantWithAuthConfig(t, svc.Enclave, proto.AuthConfig{
Playfab: proto.AuthPlayfabConfig{
Enabled: true,
Expand Down
6 changes: 3 additions & 3 deletions rpc/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ func initRPC(t *testing.T, options ...func(*config.Config)) *rpc.RPC {
opt(cfg)
}

svc, err := rpc.New(cfg, &http.Client{Transport: &testTransport{RoundTripper: http.DefaultTransport}})
svc, err := rpc.New(cfg, &testTransport{RoundTripper: http.DefaultTransport})
if err != nil {
t.Fatal(err)
}
svc.Wallets = newWalletServiceMock(nil)
return svc
}

func initRPCWithClient(t *testing.T, client *http.Client, options ...func(*config.Config)) *rpc.RPC {
func initRPCWithClient(t *testing.T, transport http.RoundTripper, options ...func(*config.Config)) *rpc.RPC {
cfg := initConfig(t, awsEndpoint)
for _, opt := range options {
opt(cfg)
}

svc, err := rpc.New(cfg, client)
svc, err := rpc.New(cfg, transport)
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 4 additions & 3 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ type RPC struct {
running int32
}

func New(cfg *config.Config, client *http.Client) (*RPC, error) {
if client == nil {
client = &http.Client{Timeout: 10 * time.Second}
func New(cfg *config.Config, transport http.RoundTripper) (*RPC, error) {
client := &http.Client{
Timeout: 30 * time.Second,
Transport: transport,
}
wrappedClient := tracing.WrapClient(client)

Expand Down

0 comments on commit 3babf64

Please sign in to comment.