aboutsummaryrefslogtreecommitdiff
path: root/roomserver/internal/input/input_events.go
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-01-31 10:39:33 +0000
committerGitHub <noreply@github.com>2022-01-31 10:39:33 +0000
commita271fde8f581389fd793e5064f88f70e90d50f66 (patch)
treeabdeb4b8c0a5ea650c6f539a150722c11f529140 /roomserver/internal/input/input_events.go
parent4281976df9d08c87d367707e6bba437bc0e72745 (diff)
Only limit context for fetching missing auth/prev events (#2131)
Diffstat (limited to 'roomserver/internal/input/input_events.go')
-rw-r--r--roomserver/internal/input/input_events.go17
1 files changed, 7 insertions, 10 deletions
diff --git a/roomserver/internal/input/input_events.go b/roomserver/internal/input/input_events.go
index 8f262ebe..2dc09667 100644
--- a/roomserver/internal/input/input_events.go
+++ b/roomserver/internal/input/input_events.go
@@ -41,7 +41,7 @@ func init() {
}
// TODO: Does this value make sense?
-const MaximumProcessingTime = time.Minute * 2
+const MaximumMissingProcessingTime = time.Minute * 2
var processRoomEventDuration = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
@@ -66,11 +66,11 @@ var processRoomEventDuration = prometheus.NewHistogramVec(
// TODO: Break up function - we should probably do transaction ID checks before calling this.
// nolint:gocyclo
func (r *Inputer) processRoomEvent(
- inctx context.Context,
+ ctx context.Context,
input *api.InputRoomEvent,
) (err error) {
select {
- case <-inctx.Done():
+ case <-ctx.Done():
// Before we do anything, make sure the context hasn't expired for this pending task.
// If it has then we'll give up straight away — it's probably a synchronous input
// request and the caller has already given up, but the inbox task was still queued.
@@ -78,13 +78,6 @@ func (r *Inputer) processRoomEvent(
default:
}
- // Wrap the context with a time limit. We'll allow no more than MaximumProcessingTime for
- // everything that we need to do for this event, or it's possible that we could end up wedging
- // the roomserver for a very long time.
- var cancel context.CancelFunc
- ctx, cancel := context.WithTimeout(inctx, MaximumProcessingTime)
- defer cancel()
-
// Measure how long it takes to process this event.
started := time.Now()
defer func() {
@@ -344,6 +337,10 @@ func (r *Inputer) fetchAuthEvents(
known map[string]*types.Event,
servers []gomatrixserverlib.ServerName,
) error {
+ var cancel context.CancelFunc
+ ctx, cancel = context.WithTimeout(ctx, MaximumMissingProcessingTime)
+ defer cancel()
+
unknown := map[string]struct{}{}
authEventIDs := event.AuthEventIDs()
if len(authEventIDs) == 0 {