From 831a76ae910544183e656125a80b079b15b755d3 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 2 Oct 2017 10:33:43 +0100 Subject: [PATCH] gb vendor updates gb vendor update github.com/matrix-org/gomatrixserverlib gb vendor update github.com/matrix-org/util --- vendor/manifest | 4 ++-- .../matrix-org/gomatrixserverlib/client.go | 15 +++++++++++++-- .../gomatrixserverlib/federationclient.go | 3 ++- vendor/src/github.com/matrix-org/util/context.go | 5 +++++ vendor/src/github.com/matrix-org/util/json.go | 2 +- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/vendor/manifest b/vendor/manifest index 28432d0e..0cc922f8 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -141,7 +141,7 @@ { "importpath": "github.com/matrix-org/gomatrixserverlib", "repository": "https://github.com/matrix-org/gomatrixserverlib", - "revision": "27d214da42f51906c2038ad3ddcffac9103c8e8f", + "revision": "fb17c27f65a0699b0d15f5311a530225b4aea5e0", "branch": "master" }, { @@ -153,7 +153,7 @@ { "importpath": "github.com/matrix-org/util", "repository": "https://github.com/matrix-org/util", - "revision": "53326ed5598b226681112cbd441f59f3cffc9c82", + "revision": "cf7e2e3871b7ae39106a1763312deaaf0c139531", "branch": "master" }, { diff --git a/vendor/src/github.com/matrix-org/gomatrixserverlib/client.go b/vendor/src/github.com/matrix-org/gomatrixserverlib/client.go index 2b9e5a8b..4274169a 100644 --- a/vendor/src/github.com/matrix-org/gomatrixserverlib/client.go +++ b/vendor/src/github.com/matrix-org/gomatrixserverlib/client.go @@ -92,7 +92,13 @@ func (f *federationTripper) RoundTrip(r *http.Request) (*http.Response, error) { if err != nil { return nil, err } + + if len(dnsResult.Addrs) == 0 { + return nil, fmt.Errorf("no address found for matrix host %v", serverName) + } + var resp *http.Response + // TODO: respect the priority and weight fields from the SRV record for _, addr := range dnsResult.Addrs { u := makeHTTPSURL(r.URL, addr) r.URL = &u @@ -100,8 +106,12 @@ func (f *federationTripper) RoundTrip(r *http.Request) (*http.Response, error) { if err == nil { return resp, nil } + util.GetLogger(r.Context()).Warnf("Error sending request to %s: %v", + u.String(), err) } - return nil, fmt.Errorf("no address found for matrix host %v", serverName) + + // just return the most recent error + return nil, err } // LookupUserInfo gets information about a user from a given matrix homeserver @@ -253,9 +263,10 @@ func (fc *Client) CreateMediaDownloadRequest( func (fc *Client) doHTTPRequest(ctx context.Context, req *http.Request) (*http.Response, error) { reqID := util.RandomString(12) logger := util.GetLogger(ctx).WithField("server", req.URL.Host).WithField("out.req.ID", reqID) + newCtx := util.ContextWithLogger(ctx, logger) logger.Infof("Outgoing request %s %s", req.Method, req.URL) - resp, err := fc.client.Do(req.WithContext(ctx)) + resp, err := fc.client.Do(req.WithContext(newCtx)) if err != nil { logger.Infof("Outgoing request %s %s failed with %v", req.Method, req.URL, err) return nil, err diff --git a/vendor/src/github.com/matrix-org/gomatrixserverlib/federationclient.go b/vendor/src/github.com/matrix-org/gomatrixserverlib/federationclient.go index 8732a3a2..06db3d86 100644 --- a/vendor/src/github.com/matrix-org/gomatrixserverlib/federationclient.go +++ b/vendor/src/github.com/matrix-org/gomatrixserverlib/federationclient.go @@ -36,6 +36,7 @@ func NewFederationClient( func (ac *FederationClient) doRequest(ctx context.Context, r FederationRequest, resBody interface{}) error { reqID := util.RandomString(12) logger := util.GetLogger(ctx).WithField("server", r.fields.Destination).WithField("out.req.ID", reqID) + newCtx := util.ContextWithLogger(ctx, logger) if err := r.Sign(ac.serverName, ac.serverKeyID, ac.serverPrivateKey); err != nil { return err @@ -47,7 +48,7 @@ func (ac *FederationClient) doRequest(ctx context.Context, r FederationRequest, } logger.Infof("Outgoing request %s %s", req.Method, req.URL) - res, err := ac.client.Do(req.WithContext(ctx)) + res, err := ac.client.Do(req.WithContext(newCtx)) if res != nil { defer res.Body.Close() // nolint: errcheck } diff --git a/vendor/src/github.com/matrix-org/util/context.go b/vendor/src/github.com/matrix-org/util/context.go index f2477a56..f1cf2de1 100644 --- a/vendor/src/github.com/matrix-org/util/context.go +++ b/vendor/src/github.com/matrix-org/util/context.go @@ -35,3 +35,8 @@ func GetLogger(ctx context.Context) *log.Entry { } return l.(*log.Entry) } + +// ContextWithLogger creates a new context, which will use the given logger. +func ContextWithLogger(ctx context.Context, l *log.Entry) context.Context { + return context.WithValue(ctx, ctxValueLogger, l) +} diff --git a/vendor/src/github.com/matrix-org/util/json.go b/vendor/src/github.com/matrix-org/util/json.go index c02f08fe..1453d89d 100644 --- a/vendor/src/github.com/matrix-org/util/json.go +++ b/vendor/src/github.com/matrix-org/util/json.go @@ -99,7 +99,7 @@ func Protect(handler http.HandlerFunc) http.HandlerFunc { func RequestWithLogging(req *http.Request) *http.Request { reqID := RandomString(12) // Set a Logger and request ID on the context - ctx := context.WithValue(req.Context(), ctxValueLogger, log.WithFields(log.Fields{ + ctx := ContextWithLogger(req.Context(), log.WithFields(log.Fields{ "req.method": req.Method, "req.path": req.URL.Path, "req.id": reqID,