2017-06-28 17:10:17 +02:00
|
|
|
// Copyright 2017 Vector Creations Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package queue
|
|
|
|
|
|
|
|
import (
|
2017-09-13 12:03:41 +02:00
|
|
|
"context"
|
2020-03-27 17:28:22 +01:00
|
|
|
"encoding/json"
|
2017-06-28 17:10:17 +02:00
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2020-04-28 11:53:07 +02:00
|
|
|
"github.com/matrix-org/dendrite/federationsender/producers"
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
"github.com/matrix-org/dendrite/federationsender/types"
|
|
|
|
"github.com/matrix-org/gomatrix"
|
2017-06-28 17:10:17 +02:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-11-16 11:12:02 +01:00
|
|
|
log "github.com/sirupsen/logrus"
|
2020-04-03 15:29:06 +02:00
|
|
|
"go.uber.org/atomic"
|
2017-06-28 17:10:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// destinationQueue is a queue of events for a single destination.
|
|
|
|
// It is responsible for sending the events to the destination and
|
|
|
|
// ensures that only one request is in flight to a given destination
|
|
|
|
// at a time.
|
|
|
|
type destinationQueue struct {
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
rsProducer *producers.RoomserverProducer // roomserver producer
|
|
|
|
client *gomatrixserverlib.FederationClient // federation client
|
|
|
|
origin gomatrixserverlib.ServerName // origin of requests
|
|
|
|
destination gomatrixserverlib.ServerName // destination of requests
|
|
|
|
running atomic.Bool // is the queue worker running?
|
2020-06-01 19:34:08 +02:00
|
|
|
backingOff atomic.Bool // true if we're backing off
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
statistics *types.ServerStatistics // statistics about this remote server
|
|
|
|
incomingPDUs chan *gomatrixserverlib.HeaderedEvent // PDUs to send
|
|
|
|
incomingEDUs chan *gomatrixserverlib.EDU // EDUs to send
|
|
|
|
incomingInvites chan *gomatrixserverlib.InviteV2Request // invites to send
|
|
|
|
lastTransactionIDs []gomatrixserverlib.TransactionID // last transaction ID
|
|
|
|
pendingPDUs []*gomatrixserverlib.HeaderedEvent // owned by backgroundSend
|
|
|
|
pendingEDUs []*gomatrixserverlib.EDU // owned by backgroundSend
|
|
|
|
pendingInvites []*gomatrixserverlib.InviteV2Request // owned by backgroundSend
|
2020-06-01 19:34:08 +02:00
|
|
|
retryServerCh chan bool // interrupts backoff
|
|
|
|
}
|
|
|
|
|
|
|
|
// retry will clear the blacklist state and attempt to send built up events to the server,
|
|
|
|
// resetting and interrupting any backoff timers.
|
|
|
|
func (oq *destinationQueue) retry() {
|
|
|
|
// TODO: We don't send all events in the case where the server has been blacklisted as we
|
|
|
|
// drop events instead then. This means we will send the oldest N events (chan size, currently 128)
|
|
|
|
// and then skip ahead a lot which feels non-ideal but equally we can't persist thousands of events
|
|
|
|
// in-memory to maybe-send it one day. Ideally we would just shove these pending events in a database
|
|
|
|
// so we can send a lot of events.
|
|
|
|
oq.statistics.Success()
|
|
|
|
// if we were backing off, swap to not backing off and interrupt the select.
|
|
|
|
// We need to use an atomic bool here to prevent multiple calls to retry() blocking on the channel
|
|
|
|
// as it is unbuffered.
|
|
|
|
if oq.backingOff.CAS(true, false) {
|
|
|
|
oq.retryServerCh <- true
|
|
|
|
}
|
|
|
|
if !oq.running.Load() {
|
|
|
|
log.Infof("Restarting queue for %s", oq.destination)
|
|
|
|
go oq.backgroundSend()
|
|
|
|
}
|
2017-06-28 17:10:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send event adds the event to the pending queue for the destination.
|
|
|
|
// If the queue is empty then it starts a background goroutine to
|
|
|
|
// start sending events to that destination.
|
2020-03-27 17:28:22 +01:00
|
|
|
func (oq *destinationQueue) sendEvent(ev *gomatrixserverlib.HeaderedEvent) {
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
if oq.statistics.Blacklisted() {
|
|
|
|
// If the destination is blacklisted then drop the event.
|
|
|
|
return
|
|
|
|
}
|
2020-04-03 15:29:06 +02:00
|
|
|
if !oq.running.Load() {
|
2017-06-28 17:10:17 +02:00
|
|
|
go oq.backgroundSend()
|
|
|
|
}
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
oq.incomingPDUs <- ev
|
2017-06-28 17:10:17 +02:00
|
|
|
}
|
|
|
|
|
2018-08-10 17:26:57 +02:00
|
|
|
// sendEDU adds the EDU event to the pending queue for the destination.
|
|
|
|
// If the queue is empty then it starts a background goroutine to
|
2020-04-03 15:29:06 +02:00
|
|
|
// start sending events to that destination.
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
func (oq *destinationQueue) sendEDU(ev *gomatrixserverlib.EDU) {
|
|
|
|
if oq.statistics.Blacklisted() {
|
|
|
|
// If the destination is blacklisted then drop the event.
|
|
|
|
return
|
|
|
|
}
|
2020-04-03 15:29:06 +02:00
|
|
|
if !oq.running.Load() {
|
|
|
|
go oq.backgroundSend()
|
|
|
|
}
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
oq.incomingEDUs <- ev
|
2020-04-03 15:29:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// sendInvite adds the invite event to the pending queue for the
|
|
|
|
// destination. If the queue is empty then it starts a background
|
|
|
|
// goroutine to start sending events to that destination.
|
|
|
|
func (oq *destinationQueue) sendInvite(ev *gomatrixserverlib.InviteV2Request) {
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
if oq.statistics.Blacklisted() {
|
|
|
|
// If the destination is blacklisted then drop the event.
|
|
|
|
return
|
|
|
|
}
|
2020-04-03 15:29:06 +02:00
|
|
|
if !oq.running.Load() {
|
2018-08-10 17:26:57 +02:00
|
|
|
go oq.backgroundSend()
|
|
|
|
}
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
oq.incomingInvites <- ev
|
2018-08-10 17:26:57 +02:00
|
|
|
}
|
|
|
|
|
2020-04-03 15:29:06 +02:00
|
|
|
// backgroundSend is the worker goroutine for sending events.
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
// nolint:gocyclo
|
2017-06-28 17:10:17 +02:00
|
|
|
func (oq *destinationQueue) backgroundSend() {
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
// Check if a worker is already running, and if it isn't, then
|
|
|
|
// mark it as started.
|
|
|
|
if !oq.running.CAS(false, true) {
|
|
|
|
return
|
|
|
|
}
|
2020-04-03 15:29:06 +02:00
|
|
|
defer oq.running.Store(false)
|
|
|
|
|
2017-06-28 17:10:17 +02:00
|
|
|
for {
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
// Wait either for incoming events, or until we hit an
|
|
|
|
// idle timeout.
|
|
|
|
select {
|
|
|
|
case pdu := <-oq.incomingPDUs:
|
|
|
|
// Ordering of PDUs is important so we add them to the end
|
|
|
|
// of the queue and they will all be added to transactions
|
|
|
|
// in order.
|
|
|
|
oq.pendingPDUs = append(oq.pendingPDUs, pdu)
|
2020-05-27 13:16:53 +02:00
|
|
|
// If there are any more things waiting in the channel queue
|
|
|
|
// then read them. This is safe because we guarantee only
|
|
|
|
// having one goroutine per destination queue, so the channel
|
|
|
|
// isn't being consumed anywhere else.
|
|
|
|
for len(oq.incomingPDUs) > 0 {
|
|
|
|
oq.pendingPDUs = append(oq.pendingPDUs, <-oq.incomingPDUs)
|
|
|
|
}
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
case edu := <-oq.incomingEDUs:
|
|
|
|
// Likewise for EDUs, although we should probably not try
|
|
|
|
// too hard with some EDUs (like typing notifications) after
|
|
|
|
// a certain amount of time has passed.
|
|
|
|
// TODO: think about EDU expiry some more
|
|
|
|
oq.pendingEDUs = append(oq.pendingEDUs, edu)
|
2020-05-27 13:16:53 +02:00
|
|
|
// If there are any more things waiting in the channel queue
|
|
|
|
// then read them. This is safe because we guarantee only
|
|
|
|
// having one goroutine per destination queue, so the channel
|
|
|
|
// isn't being consumed anywhere else.
|
|
|
|
for len(oq.incomingEDUs) > 0 {
|
|
|
|
oq.pendingEDUs = append(oq.pendingEDUs, <-oq.incomingEDUs)
|
|
|
|
}
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
case invite := <-oq.incomingInvites:
|
|
|
|
// There's no strict ordering requirement for invites like
|
|
|
|
// there is for transactions, so we put the invite onto the
|
|
|
|
// front of the queue. This means that if an invite that is
|
|
|
|
// stuck failing already, that it won't block our new invite
|
|
|
|
// from being sent.
|
|
|
|
oq.pendingInvites = append(
|
|
|
|
[]*gomatrixserverlib.InviteV2Request{invite},
|
|
|
|
oq.pendingInvites...,
|
|
|
|
)
|
2020-05-27 13:16:53 +02:00
|
|
|
// If there are any more things waiting in the channel queue
|
|
|
|
// then read them. This is safe because we guarantee only
|
|
|
|
// having one goroutine per destination queue, so the channel
|
|
|
|
// isn't being consumed anywhere else.
|
|
|
|
for len(oq.incomingInvites) > 0 {
|
|
|
|
oq.pendingInvites = append(oq.pendingInvites, <-oq.incomingInvites)
|
|
|
|
}
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
case <-time.After(time.Second * 30):
|
|
|
|
// The worker is idle so stop the goroutine. It'll
|
|
|
|
// get restarted automatically the next time we
|
|
|
|
// get an event.
|
2017-06-28 17:10:17 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
// If we are backing off this server then wait for the
|
2020-06-01 19:34:08 +02:00
|
|
|
// backoff duration to complete first, or until explicitly
|
|
|
|
// told to retry.
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
if backoff, duration := oq.statistics.BackoffDuration(); backoff {
|
2020-06-01 19:34:08 +02:00
|
|
|
oq.backingOff.Store(true)
|
|
|
|
select {
|
|
|
|
case <-time.After(duration):
|
|
|
|
case <-oq.retryServerCh:
|
|
|
|
}
|
|
|
|
oq.backingOff.Store(false)
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// How many things do we have waiting?
|
|
|
|
numPDUs := len(oq.pendingPDUs)
|
|
|
|
numEDUs := len(oq.pendingEDUs)
|
|
|
|
numInvites := len(oq.pendingInvites)
|
|
|
|
|
|
|
|
// If we have pending PDUs or EDUs then construct a transaction.
|
|
|
|
if numPDUs > 0 || numEDUs > 0 {
|
|
|
|
// Try sending the next transaction and see what happens.
|
|
|
|
transaction, terr := oq.nextTransaction(oq.pendingPDUs, oq.pendingEDUs, oq.statistics.SuccessCount())
|
|
|
|
if terr != nil {
|
|
|
|
// We failed to send the transaction.
|
|
|
|
if giveUp := oq.statistics.Failure(); giveUp {
|
|
|
|
// It's been suggested that we should give up because
|
|
|
|
// the backoff has exceeded a maximum allowable value.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else if transaction {
|
|
|
|
// If we successfully sent the transaction then clear out
|
|
|
|
// the pending events and EDUs.
|
|
|
|
oq.statistics.Success()
|
|
|
|
// Reallocate so that the underlying arrays can be GC'd, as
|
|
|
|
// opposed to growing forever.
|
|
|
|
for i := 0; i < numPDUs; i++ {
|
|
|
|
oq.pendingPDUs[i] = nil
|
|
|
|
}
|
|
|
|
for i := 0; i < numEDUs; i++ {
|
|
|
|
oq.pendingEDUs[i] = nil
|
|
|
|
}
|
|
|
|
oq.pendingPDUs = append(
|
|
|
|
[]*gomatrixserverlib.HeaderedEvent{},
|
|
|
|
oq.pendingPDUs[numPDUs:]...,
|
|
|
|
)
|
|
|
|
oq.pendingEDUs = append(
|
|
|
|
[]*gomatrixserverlib.EDU{},
|
|
|
|
oq.pendingEDUs[numEDUs:]...,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try sending the next invite and see what happens.
|
|
|
|
if numInvites > 0 {
|
|
|
|
sent, ierr := oq.nextInvites(oq.pendingInvites)
|
|
|
|
if ierr != nil {
|
|
|
|
// We failed to send the transaction so increase the
|
|
|
|
// backoff and give it another go shortly.
|
|
|
|
if giveUp := oq.statistics.Failure(); giveUp {
|
|
|
|
// It's been suggested that we should give up because
|
|
|
|
// the backoff has exceeded a maximum allowable value.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else if sent > 0 {
|
|
|
|
// If we successfully sent the invites then clear out
|
|
|
|
// the pending invites.
|
|
|
|
oq.statistics.Success()
|
|
|
|
// Reallocate so that the underlying array can be GC'd, as
|
|
|
|
// opposed to growing forever.
|
|
|
|
oq.pendingInvites = append(
|
|
|
|
[]*gomatrixserverlib.InviteV2Request{},
|
|
|
|
oq.pendingInvites[sent:]...,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2017-06-28 17:10:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-03 15:29:06 +02:00
|
|
|
// nextTransaction creates a new transaction from the pending event
|
|
|
|
// queue and sends it. Returns true if a transaction was sent or
|
|
|
|
// false otherwise.
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
func (oq *destinationQueue) nextTransaction(
|
|
|
|
pendingPDUs []*gomatrixserverlib.HeaderedEvent,
|
|
|
|
pendingEDUs []*gomatrixserverlib.EDU,
|
|
|
|
sentCounter uint32,
|
|
|
|
) (bool, error) {
|
2020-02-28 15:54:51 +01:00
|
|
|
t := gomatrixserverlib.Transaction{
|
2020-03-27 17:28:22 +01:00
|
|
|
PDUs: []json.RawMessage{},
|
2020-02-28 15:54:51 +01:00
|
|
|
EDUs: []gomatrixserverlib.EDU{},
|
|
|
|
}
|
2017-06-28 17:10:17 +02:00
|
|
|
now := gomatrixserverlib.AsTimestamp(time.Now())
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
t.TransactionID = gomatrixserverlib.TransactionID(fmt.Sprintf("%d-%d", now, sentCounter))
|
2017-06-28 17:10:17 +02:00
|
|
|
t.Origin = oq.origin
|
|
|
|
t.Destination = oq.destination
|
|
|
|
t.OriginServerTS = now
|
|
|
|
t.PreviousIDs = oq.lastTransactionIDs
|
|
|
|
if t.PreviousIDs == nil {
|
|
|
|
t.PreviousIDs = []gomatrixserverlib.TransactionID{}
|
|
|
|
}
|
2018-08-10 17:26:57 +02:00
|
|
|
|
2017-06-28 17:10:17 +02:00
|
|
|
oq.lastTransactionIDs = []gomatrixserverlib.TransactionID{t.TransactionID}
|
2018-08-10 17:26:57 +02:00
|
|
|
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
for _, pdu := range pendingPDUs {
|
2020-03-27 17:28:22 +01:00
|
|
|
// Append the JSON of the event, since this is a json.RawMessage type in the
|
|
|
|
// gomatrixserverlib.Transaction struct
|
|
|
|
t.PDUs = append(t.PDUs, (*pdu).JSON())
|
2017-06-28 17:10:17 +02:00
|
|
|
}
|
2018-08-10 17:26:57 +02:00
|
|
|
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
for _, edu := range pendingEDUs {
|
2018-08-10 17:26:57 +02:00
|
|
|
t.EDUs = append(t.EDUs, *edu)
|
|
|
|
}
|
|
|
|
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
logrus.WithField("server_name", oq.destination).Infof("Sending transaction %q containing %d PDUs, %d EDUs", t.TransactionID, len(t.PDUs), len(t.EDUs))
|
2020-04-03 15:29:06 +02:00
|
|
|
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
// TODO: we should check for 500-ish fails vs 400-ish here,
|
|
|
|
// since we shouldn't queue things indefinitely in response
|
|
|
|
// to a 400-ish error
|
2020-04-03 15:29:06 +02:00
|
|
|
_, err := oq.client.SendTransaction(context.TODO(), t)
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
switch e := err.(type) {
|
|
|
|
case nil:
|
|
|
|
// No error was returned so the transaction looks to have
|
|
|
|
// been successfully sent.
|
|
|
|
return true, nil
|
|
|
|
case gomatrix.HTTPError:
|
|
|
|
// We received a HTTP error back. In this instance we only
|
|
|
|
// should report an error if
|
|
|
|
if e.Code >= 400 && e.Code <= 499 {
|
|
|
|
// We tried but the remote side has sent back a client error.
|
|
|
|
// It's no use retrying because it will happen again.
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
// Otherwise, report that we failed to send the transaction
|
|
|
|
// and we will retry again.
|
|
|
|
return false, err
|
|
|
|
default:
|
2020-04-03 15:29:06 +02:00
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"destination": oq.destination,
|
|
|
|
log.ErrorKey: err,
|
|
|
|
}).Info("problem sending transaction")
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
return false, err
|
2020-04-03 15:29:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextInvite takes pending invite events from the queue and sends
|
|
|
|
// them. Returns true if a transaction was sent or false otherwise.
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
func (oq *destinationQueue) nextInvites(
|
|
|
|
pendingInvites []*gomatrixserverlib.InviteV2Request,
|
|
|
|
) (int, error) {
|
|
|
|
done := 0
|
|
|
|
for _, inviteReq := range pendingInvites {
|
2020-04-28 11:53:07 +02:00
|
|
|
ev, roomVersion := inviteReq.Event(), inviteReq.RoomVersion()
|
2020-04-03 15:29:06 +02:00
|
|
|
|
2020-04-28 11:53:07 +02:00
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"event_id": ev.EventID(),
|
|
|
|
"room_version": roomVersion,
|
|
|
|
"destination": oq.destination,
|
|
|
|
}).Info("sending invite")
|
|
|
|
|
|
|
|
inviteRes, err := oq.client.SendInviteV2(
|
2020-04-03 15:29:06 +02:00
|
|
|
context.TODO(),
|
|
|
|
oq.destination,
|
|
|
|
*inviteReq,
|
2020-04-28 11:53:07 +02:00
|
|
|
)
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
switch e := err.(type) {
|
|
|
|
case nil:
|
|
|
|
done++
|
|
|
|
case gomatrix.HTTPError:
|
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"event_id": ev.EventID(),
|
|
|
|
"state_key": ev.StateKey(),
|
|
|
|
"destination": oq.destination,
|
|
|
|
"status_code": e.Code,
|
|
|
|
}).WithError(err).Error("failed to send invite due to HTTP error")
|
|
|
|
// Check whether we should do something about the error or
|
|
|
|
// just accept it as unavoidable.
|
|
|
|
if e.Code >= 400 && e.Code <= 499 {
|
|
|
|
// We tried but the remote side has sent back a client error.
|
|
|
|
// It's no use retrying because it will happen again.
|
|
|
|
done++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return done, err
|
|
|
|
default:
|
2020-04-03 15:29:06 +02:00
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"event_id": ev.EventID(),
|
|
|
|
"state_key": ev.StateKey(),
|
|
|
|
"destination": oq.destination,
|
|
|
|
}).WithError(err).Error("failed to send invite")
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
return done, err
|
2020-04-28 11:53:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if _, err = oq.rsProducer.SendInviteResponse(
|
|
|
|
context.TODO(),
|
|
|
|
inviteRes,
|
|
|
|
roomVersion,
|
|
|
|
); err != nil {
|
|
|
|
log.WithFields(log.Fields{
|
|
|
|
"event_id": ev.EventID(),
|
|
|
|
"state_key": ev.StateKey(),
|
|
|
|
"destination": oq.destination,
|
|
|
|
}).WithError(err).Error("failed to return signed invite to roomserver")
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
return done, err
|
2020-04-03 15:29:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 13:42:06 +02:00
|
|
|
return done, nil
|
2017-06-28 17:10:17 +02:00
|
|
|
}
|