From 5465f31d7131f2659c44ac43119118c116cdd5a0 Mon Sep 17 00:00:00 2001 From: Bartek Nowotarski Date: Wed, 19 Jul 2017 15:52:23 +0200 Subject: [PATCH] Use http.Client with Timeout --- src/github.com/stellar/gateway/bridge/app.go | 20 ++++++++++++------ .../stellar/gateway/compliance/app.go | 21 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/github.com/stellar/gateway/bridge/app.go b/src/github.com/stellar/gateway/bridge/app.go index 461ae53..d05d506 100644 --- a/src/github.com/stellar/gateway/bridge/app.go +++ b/src/github.com/stellar/gateway/bridge/app.go @@ -139,20 +139,28 @@ func NewApp(config config.Config, migrateFlag bool) (app *App, err error) { requestHandler := handlers.RequestHandler{} - federationClient := &federation.Client{ - HTTP: http.DefaultClient, - StellarTOML: stellartoml.DefaultClient, + httpClientWithTimeout := http.Client{ + Timeout: 10 * time.Second, + } + + stellartomlClient := stellartoml.Client{ + HTTP: &httpClientWithTimeout, + } + + federationClient := federation.Client{ + HTTP: &httpClientWithTimeout, + StellarTOML: &stellartomlClient, } err = g.Provide( &inject.Object{Value: &requestHandler}, &inject.Object{Value: &config}, - &inject.Object{Value: stellartoml.DefaultClient}, - &inject.Object{Value: federationClient}, + &inject.Object{Value: &stellartomlClient}, + &inject.Object{Value: &federationClient}, &inject.Object{Value: &h}, &inject.Object{Value: &ts}, &inject.Object{Value: &paymentListener}, - &inject.Object{Value: &http.Client{}}, + &inject.Object{Value: &httpClientWithTimeout}, ) if err != nil { diff --git a/src/github.com/stellar/gateway/compliance/app.go b/src/github.com/stellar/gateway/compliance/app.go index 13e0e4d..d9e5d17 100644 --- a/src/github.com/stellar/gateway/compliance/app.go +++ b/src/github.com/stellar/gateway/compliance/app.go @@ -5,6 +5,7 @@ import ( log "github.com/Sirupsen/logrus" "net/http" "os" + "time" "github.com/facebookgo/inject" "github.com/stellar/gateway/compliance/config" @@ -62,9 +63,17 @@ func NewApp(config config.Config, migrateFlag bool) (app *App, err error) { requestHandler := handlers.RequestHandler{} - federationClient := &federation.Client{ - HTTP: http.DefaultClient, - StellarTOML: stellartoml.DefaultClient, + httpClientWithTimeout := http.Client{ + Timeout: 10 * time.Second, + } + + stellartomlClient := stellartoml.Client{ + HTTP: &httpClientWithTimeout, + } + + federationClient := federation.Client{ + HTTP: &httpClientWithTimeout, + StellarTOML: &stellartomlClient, } err = g.Provide( @@ -73,9 +82,9 @@ func NewApp(config config.Config, migrateFlag bool) (app *App, err error) { &inject.Object{Value: &entityManager}, &inject.Object{Value: &repository}, &inject.Object{Value: &crypto.SignerVerifier{}}, - &inject.Object{Value: stellartoml.DefaultClient}, - &inject.Object{Value: federationClient}, - &inject.Object{Value: &http.Client{}}, + &inject.Object{Value: &stellartomlClient}, + &inject.Object{Value: &federationClient}, + &inject.Object{Value: &httpClientWithTimeout}, &inject.Object{Value: &handlers.NonceGenerator{}}, )