aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonnie Ebrin <ebrin.ronnie@protonmail.com>2020-12-04 15:08:17 +0100
committerGitHub <noreply@github.com>2020-12-04 14:08:17 +0000
commita677a288bd3344a5d31080be047125043ada75dc (patch)
tree4494817ecad6728863f397fa151f7cad030b1256
parent1ce9c524420bc6a7b08748ca736284382581ab56 (diff)
federationsender/roomserver: don't panic while federation is disabled (#1615)
-rw-r--r--federationsender/consumers/roomserver.go21
-rw-r--r--federationsender/queue/queue.go16
2 files changed, 28 insertions, 9 deletions
diff --git a/federationsender/consumers/roomserver.go b/federationsender/consumers/roomserver.go
index 13c415bc..b53cb251 100644
--- a/federationsender/consumers/roomserver.go
+++ b/federationsender/consumers/roomserver.go
@@ -94,13 +94,20 @@ func (s *OutputRoomEventConsumer) onMessage(msg *sarama.ConsumerMessage) error {
}
if err := s.processMessage(*output.NewRoomEvent); err != nil {
- // panic rather than continue with an inconsistent database
- log.WithFields(log.Fields{
- "event": string(ev.JSON()),
- "add": output.NewRoomEvent.AddsStateEventIDs,
- "del": output.NewRoomEvent.RemovesStateEventIDs,
- log.ErrorKey: err,
- }).Panicf("roomserver output log: write room event failure")
+ switch err.(type) {
+ case *queue.ErrorFederationDisabled:
+ log.WithField("error", output.Type).Info(
+ err.Error(),
+ )
+ default:
+ // panic rather than continue with an inconsistent database
+ log.WithFields(log.Fields{
+ "event": string(ev.JSON()),
+ "add": output.NewRoomEvent.AddsStateEventIDs,
+ "del": output.NewRoomEvent.RemovesStateEventIDs,
+ log.ErrorKey: err,
+ }).Panicf("roomserver output log: write room event failure")
+ }
return nil
}
default:
diff --git a/federationsender/queue/queue.go b/federationsender/queue/queue.go
index 95d37b2b..d45af868 100644
--- a/federationsender/queue/queue.go
+++ b/federationsender/queue/queue.go
@@ -122,13 +122,23 @@ func (oqs *OutgoingQueues) getQueue(destination gomatrixserverlib.ServerName) *d
return oq
}
+type ErrorFederationDisabled struct {
+ Message string
+}
+
+func (e *ErrorFederationDisabled) Error() string {
+ return e.Message
+}
+
// SendEvent sends an event to the destinations
func (oqs *OutgoingQueues) SendEvent(
ev *gomatrixserverlib.HeaderedEvent, origin gomatrixserverlib.ServerName,
destinations []gomatrixserverlib.ServerName,
) error {
if oqs.disabled {
- return fmt.Errorf("federation is disabled")
+ return &ErrorFederationDisabled{
+ Message: "Federation disabled",
+ }
}
if origin != oqs.origin {
// TODO: Support virtual hosting; gh issue #577.
@@ -190,7 +200,9 @@ func (oqs *OutgoingQueues) SendEDU(
destinations []gomatrixserverlib.ServerName,
) error {
if oqs.disabled {
- return fmt.Errorf("federation is disabled")
+ return &ErrorFederationDisabled{
+ Message: "Federation disabled",
+ }
}
if origin != oqs.origin {
// TODO: Support virtual hosting; gh issue #577.