Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid logging issues if we still could fetch keys #422

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/matrix-org/util"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ed25519"
)

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

fetched, err := fetcher.FetchKeys(ctx, keyRequests)
if err != nil {
fetcherLogger.WithError(err).Warn("Failed to request keys from fetcher")
continue
}

if len(fetched) == 0 {
fetcherLogger.Warn("Failed to retrieve any keys")
continue
}

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

// We for some reason failed to fetch keys for some servers
if len(keyRequests) > 0 {
requestedServers := make([]string, 0, len(keyRequests))
for reqs := range keyRequests {
requestedServers = append(requestedServers, string(reqs.ServerName))
}

logger.WithFields(logrus.Fields{
"servers": requestedServers,
"fetchers": len(k.KeyFetchers),
}).Warn("failed to fetch keys for some servers")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without stating which servers this isn't very helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requestedServers is the list of the servers we failed to fetch keys for.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that wasn't clear. LGTM then!

}

// Now that we've fetched all of the keys we need, try to check
// if the requests are valid.
k.checkUsingKeys(requests, results, keyIDs, keysFetched)
Expand Down Expand Up @@ -487,7 +499,6 @@ func (d DirectKeyFetcher) FetcherName() string {
func (d *DirectKeyFetcher) FetchKeys(
ctx context.Context, requests map[PublicKeyLookupRequest]spec.Timestamp,
) (map[PublicKeyLookupRequest]PublicKeyLookupResult, error) {
fetcherLogger := util.GetLogger(ctx).WithField("fetcher", d.FetcherName())

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