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