More tweaks

This commit is contained in:
Till Faelligen 2022-09-08 11:22:05 +02:00
parent 6b303ca527
commit 92e138efd0
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E
2 changed files with 17 additions and 1 deletions

View file

@ -4,11 +4,13 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"net/http" "net/http"
"net/url"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/matrix-org/gomatrix" "github.com/matrix-org/gomatrix"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util" "github.com/matrix-org/util"
"github.com/sirupsen/logrus"
"github.com/matrix-org/dendrite/federationapi/api" "github.com/matrix-org/dendrite/federationapi/api"
"github.com/matrix-org/dendrite/internal/httputil" "github.com/matrix-org/dendrite/internal/httputil"
@ -235,7 +237,13 @@ func federationClientError(err error) error {
return &api.FederationClientError{ return &api.FederationClientError{
Code: ferr.Code, Code: ferr.Code,
} }
case *url.Error: // e.g. certificate error, unable to connect
return &api.FederationClientError{
Err: ferr.Error(),
Code: 400,
}
default: default:
logrus.Debugf("Unknown error: %T", ferr)
return &api.FederationClientError{ return &api.FederationClientError{
Err: err.Error(), Err: err.Error(),
} }

View file

@ -397,11 +397,19 @@ userLoop:
if ctx.Err() != nil { if ctx.Err() != nil {
// we've timed out, give up and go to the back of the queue to let another server be processed. // we've timed out, give up and go to the back of the queue to let another server be processed.
failCount += 1 failCount += 1
waitTime = time.Minute * 10
break break
} }
res, err := u.fedClient.GetUserDevices(ctx, serverName, userID) res, err := u.fedClient.GetUserDevices(ctx, serverName, userID)
if err != nil { if err != nil {
failCount += 1 failCount += 1
select {
case <-ctx.Done():
// we've timed out, give up and go to the back of the queue to let another server be processed.
waitTime = time.Minute * 10
break userLoop
default:
}
switch e := err.(type) { switch e := err.(type) {
case *fedsenderapi.FederationClientError: case *fedsenderapi.FederationClientError:
if e.RetryAfter > 0 { if e.RetryAfter > 0 {
@ -428,7 +436,7 @@ userLoop:
// This is to avoid spamming remote servers, which may not be Matrix servers anymore. // This is to avoid spamming remote servers, which may not be Matrix servers anymore.
if e.Code >= 300 { if e.Code >= 300 {
waitTime = time.Hour waitTime = time.Hour
logrus.WithError(e).Error("GetUserDevices returned gomatrix.HTTPError") logger.WithError(e).Error("GetUserDevices returned gomatrix.HTTPError")
break userLoop break userLoop
} }
default: default: