From d9416d9647e3423fa6ca4ef9a641de0ac0e0e28e Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Sat, 3 May 2025 09:24:38 +0200 Subject: [PATCH] Give each HTTP request its own context to avoid timing out subsequent notification requests if the first already times out. Signed-off-by: Till Faelligen <2353100+S7evinK@users.noreply.github.com> --- userapi/consumers/roomserver.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/userapi/consumers/roomserver.go b/userapi/consumers/roomserver.go index a79441f3..c2b67682 100644 --- a/userapi/consumers/roomserver.go +++ b/userapi/consumers/roomserver.go @@ -604,7 +604,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype // ordering guarantees we must provide. go func() { // This background processing cannot be tied to a request. - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second*time.Duration(len(devicesByURLAndFormat))) defer cancel() var rejected []*pushgateway.Device @@ -615,13 +615,17 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype continue } + // Give each HTTP request its own context. + httpCtx, cancel := context.WithTimeout(ctx, 30*time.Second) + defer cancel() + // UNSPEC: the specification suggests there can be // more than one device per request. There is at least // one Sytest that expects one HTTP request per // device, rather than per URL. For now, we must // notify each one separately. for _, dev := range devices { - rej, err := s.notifyHTTP(ctx, event, url, format, []*pushgateway.Device{dev}, mem.Localpart, roomName, int(userNumUnreadNotifs)) + rej, err := s.notifyHTTP(httpCtx, event, url, format, []*pushgateway.Device{dev}, mem.Localpart, roomName, int(userNumUnreadNotifs)) if err != nil { log.WithFields(log.Fields{ "event_id": event.EventID(),