Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Give up on loops when the context expires (#1891)
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander authored Jun 30, 2021
1 parent 3afb161 commit 0e69212
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions federationapi/routing/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"database/sql"
"encoding/json"
"errors"
"fmt"
"net/http"
"sync"
Expand Down Expand Up @@ -570,6 +571,9 @@ withNextEvent:
tx, err := t.federation.GetEvent(ctx, server, missingAuthEventID)
if err != nil {
logger.WithError(err).Warnf("Failed to retrieve auth event %q", missingAuthEventID)
if errors.Is(err, context.DeadlineExceeded) {
return err
}
continue withNextServer
}
ev, err := gomatrixserverlib.NewEventFromUntrustedJSON(tx.PDUs[0], stateResp.RoomVersion)
Expand Down Expand Up @@ -958,6 +962,9 @@ func (t *txnReq) getMissingEvents(ctx context.Context, e *gomatrixserverlib.Even
break
} else {
logger.WithError(err).Errorf("%s pushed us an event but %q did not respond to /get_missing_events", t.Origin, server)
if errors.Is(err, context.DeadlineExceeded) {
break
}
}
}

Expand Down Expand Up @@ -1218,6 +1225,9 @@ func (t *txnReq) lookupEvent(ctx context.Context, roomVersion gomatrixserverlib.
txn, err := t.federation.GetEvent(ctx, serverName, missingEventID)
if err != nil || len(txn.PDUs) == 0 {
util.GetLogger(ctx).WithError(err).WithField("event_id", missingEventID).Warn("Failed to get missing /event for event ID")
if errors.Is(err, context.DeadlineExceeded) {
break
}
continue
}
event, err = gomatrixserverlib.NewEventFromUntrustedJSON(txn.PDUs[0], roomVersion)
Expand Down

0 comments on commit 0e69212

Please sign in to comment.