Skip to content

[notifications] Give each HTTP request its own context #3569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions userapi/consumers/roomserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ 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)
// We're generous with the "global" timeout, each HTTP request gets its own context with
// at most 30 seconds below.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

var rejected []*pushgateway.Device
Expand All @@ -621,7 +623,10 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *rstype
// 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))
// Give each HTTP request its own context.
httpCtx, httpCancel := context.WithTimeout(ctx, 30*time.Second)
rej, err := s.notifyHTTP(httpCtx, event, url, format, []*pushgateway.Device{dev}, mem.Localpart, roomName, int(userNumUnreadNotifs))
httpCancel()
if err != nil {
log.WithFields(log.Fields{
"event_id": event.EventID(),
Expand Down
Loading