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 <minecnly@gmail.com>
This commit is contained in:
Cnly 2019-06-27 04:02:43 +08:00
parent e7cf44946f
commit 74fd292403

View file

@ -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