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>
This commit is contained in:
Till Faelligen 2025-05-03 09:24:38 +02:00
parent c15dee80f2
commit d9416d9647
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E

View file

@ -604,7 +604,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
// ordering guarantees we must provide. // ordering guarantees we must provide.
go func() { go func() {
// This background processing cannot be tied to a request. // 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() defer cancel()
var rejected []*pushgateway.Device var rejected []*pushgateway.Device
@ -615,13 +615,17 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
continue 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 // UNSPEC: the specification suggests there can be
// more than one device per request. There is at least // more than one device per request. There is at least
// one Sytest that expects one HTTP request per // one Sytest that expects one HTTP request per
// device, rather than per URL. For now, we must // device, rather than per URL. For now, we must
// notify each one separately. // notify each one separately.
for _, dev := range devices { 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 { if err != nil {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"event_id": event.EventID(), "event_id": event.EventID(),