Skip to content

Commit 2beadf1

Browse files
authored
Avoid logging issues if we still could fetch keys (#422)
To avoid confusion about e.g. being unable to fetch keys from matrix.org.
1 parent 58af9a2 commit 2beadf1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

keyring.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/matrix-org/gomatrixserverlib/spec"
1212
"github.com/matrix-org/util"
13+
"github.com/sirupsen/logrus"
1314
"golang.org/x/crypto/ed25519"
1415
)
1516

@@ -271,12 +272,10 @@ func (k KeyRing) VerifyJSONs(ctx context.Context, requests []VerifyJSONRequest)
271272

272273
fetched, err := fetcher.FetchKeys(ctx, keyRequests)
273274
if err != nil {
274-
fetcherLogger.WithError(err).Warn("Failed to request keys from fetcher")
275275
continue
276276
}
277277

278278
if len(fetched) == 0 {
279-
fetcherLogger.Warn("Failed to retrieve any keys")
280279
continue
281280
}
282281

@@ -290,6 +289,19 @@ func (k KeyRing) VerifyJSONs(ctx context.Context, requests []VerifyJSONRequest)
290289
}
291290
}
292291

292+
// We for some reason failed to fetch keys for some servers
293+
if len(keyRequests) > 0 {
294+
requestedServers := make([]string, 0, len(keyRequests))
295+
for reqs := range keyRequests {
296+
requestedServers = append(requestedServers, string(reqs.ServerName))
297+
}
298+
299+
logger.WithFields(logrus.Fields{
300+
"servers": requestedServers,
301+
"fetchers": len(k.KeyFetchers),
302+
}).Warn("failed to fetch keys for some servers")
303+
}
304+
293305
// Now that we've fetched all of the keys we need, try to check
294306
// if the requests are valid.
295307
k.checkUsingKeys(requests, results, keyIDs, keysFetched)
@@ -487,7 +499,6 @@ func (d DirectKeyFetcher) FetcherName() string {
487499
func (d *DirectKeyFetcher) FetchKeys(
488500
ctx context.Context, requests map[PublicKeyLookupRequest]spec.Timestamp,
489501
) (map[PublicKeyLookupRequest]PublicKeyLookupResult, error) {
490-
fetcherLogger := util.GetLogger(ctx).WithField("fetcher", d.FetcherName())
491502

492503
localServerRequests := []PublicKeyLookupRequest{}
493504
byServer := map[spec.ServerName]map[PublicKeyLookupRequest]spec.Timestamp{}
@@ -548,7 +559,6 @@ func (d *DirectKeyFetcher) FetchKeys(
548559
serverResults, err = d.fetchNotaryKeysForServer(ctx, server)
549560
if err != nil {
550561
// TODO: Should we actually be erroring here? or should we just drop those keys from the result map?
551-
fetcherLogger.WithError(err).Error("Failed to fetch key for server")
552562
continue
553563
}
554564
}

0 commit comments

Comments
 (0)