Enforce a limit of 20s per server, 5 mins total

This commit is contained in:
Neil Alexander 2022-08-03 17:23:41 +01:00
parent 0f01780282
commit c2a749745d
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -668,15 +668,17 @@ func (t *missingStateReq) lookupMissingStateViaStateIDs(ctx context.Context, roo
var stateIDs gomatrixserverlib.RespStateIDs
var err error
count := 0
totalctx, totalcancel := context.WithTimeout(ctx, time.Minute*5)
for _, serverName := range t.servers {
reqctx, cancel := context.WithTimeout(ctx, time.Second*30)
reqctx, reqcancel := context.WithTimeout(totalctx, time.Second*20)
stateIDs, err = t.federation.LookupStateIDs(reqctx, serverName, roomID, eventID)
cancel()
reqcancel()
if err == nil {
break
}
count++
}
totalcancel()
if err != nil {
return nil, fmt.Errorf("t.federation.LookupStateIDs tried %d server(s), last error: %w", count, err)
}