From 7dbdda964189f5542048c06ce5ffc6d4da1814e6 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Wed, 11 May 2022 08:48:52 +0200 Subject: [PATCH] Return CurrentPosition if the request timed out --- syncapi/sync/requestpool.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 30c490df0..048b57b9b 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -250,6 +250,13 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi. giveup := func() util.JSONResponse { syncReq.Log.Debugln("Responding to sync since client gave up or timeout was reached") syncReq.Response.NextBatch = syncReq.Since + + // The request timed out and wasn't woken up by the streams, advance NextBatch to avoid hitting + // /sync and returning immediately + if !timer.Stop() { + syncReq.Log.Traceln("Advancing next batch, as request wasn't woken by streams") + syncReq.Response.NextBatch = rp.Notifier.CurrentPosition() + } // We should always try to include OTKs in sync responses, otherwise clients might upload keys // even if that's not required. See also: // https://github.com/matrix-org/synapse/blob/29f06704b8871a44926f7c99e73cf4a978fb8e81/synapse/rest/client/sync.py#L276-L281