From 74fd292403a3f3256f0b6d7e858b531631c17c54 Mon Sep 17 00:00:00 2001 From: Cnly Date: Thu, 27 Jun 2019 04:02:43 +0800 Subject: [PATCH] Fix latest sync pos used as since pos in requestpool.go Previously, currPos, obtained using notifier.CurrentPosition(), is passed to GetNotifyChannel. Since this is already the latest position on the server, the client won't get updates until (1) a even newer event arrives at the server, or (2) the /sync request times out. (2) above is possible because when it times out, notifier calculates currentSyncForUser based on syncReq, which contains the correct since pos token that the client sent the server. Signed-off-by: Alex Chen --- syncapi/sync/requestpool.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 6d272e9f5..1c91fa467 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -63,11 +63,9 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype "timeout": syncReq.timeout, }).Info("Incoming /sync request") - currPos := rp.notifier.CurrentPosition() - // If this is an initial sync or timeout=0 we return immediately if syncReq.since == nil || syncReq.timeout == 0 { - syncData, err = rp.currentSyncForUser(*syncReq, currPos) + syncData, err = rp.currentSyncForUser(*syncReq, rp.notifier.CurrentPosition()) if err != nil { return httputil.LogThenError(req, err) } @@ -92,11 +90,14 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype // respond with, so we skip the return an go back to waiting for content to // be sent down or the request timing out. var hasTimedOut bool + var currPos types.SyncPosition + sincePos := *syncReq.since for { select { // Wait for notifier to wake us up - case <-userStreamListener.GetNotifyChannel(currPos): + case <-userStreamListener.GetNotifyChannel(sincePos): currPos = userStreamListener.GetStreamPosition() + sincePos = currPos // Or for timeout to expire case <-timer.C: // We just need to ensure we get out of the select after reaching the