From c31a1767f77fb62892b5c34a5387ef9f059dec4b Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 6 Jan 2021 17:05:42 +0000 Subject: [PATCH] Don't reset next batch position on timeout --- syncapi/sync/requestpool.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 0820474c7..d03748248 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -168,15 +168,21 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi. // Use a subcontext so that we don't keep the StreamNotifyAfter // goroutines alive any longer than they really need to be. waitctx, waitcancel := context.WithCancel(syncReq.Context) + giveup := func() util.JSONResponse { + waitcancel() + syncReq.Response.NextBatch = syncReq.Since + return util.JSONResponse{ + Code: http.StatusOK, + JSON: syncReq.Response, + } + } select { case <-waitctx.Done(): // Caller gave up - waitcancel() - return util.JSONResponse{Code: http.StatusOK, JSON: syncReq.Response} + return giveup() case <-timer.C: // Timeout reached - waitcancel() - return util.JSONResponse{Code: http.StatusOK, JSON: syncReq.Response} + return giveup() case <-rp.pduStream.NotifyAfter(waitctx, syncReq.Since.PDUPosition): case <-rp.typingStream.NotifyAfter(waitctx, syncReq.Since.TypingPosition):