Don't reset next batch position on timeout

This commit is contained in:
Neil Alexander 2021-01-06 17:05:42 +00:00
parent 722510ac9f
commit c31a1767f7
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

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