Fix timed out syncs

This commit is contained in:
Neil Alexander 2021-01-06 16:58:07 +00:00
parent a588f9061b
commit 722510ac9f
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -144,8 +144,6 @@ var waitingSyncRequests = prometheus.NewGauge(
// called in a dedicated goroutine for this request. This function will block the goroutine // called in a dedicated goroutine for this request. This function will block the goroutine
// until a response is ready, or it times out. // until a response is ready, or it times out.
func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi.Device) util.JSONResponse { func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi.Device) util.JSONResponse {
var syncData *types.Response
// Extract values from request // Extract values from request
syncReq, err := newSyncRequest(req, *device, rp.db) syncReq, err := newSyncRequest(req, *device, rp.db)
if err != nil { if err != nil {
@ -174,11 +172,11 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *userapi.
select { select {
case <-waitctx.Done(): // Caller gave up case <-waitctx.Done(): // Caller gave up
waitcancel() waitcancel()
return util.JSONResponse{Code: http.StatusOK, JSON: syncData} return util.JSONResponse{Code: http.StatusOK, JSON: syncReq.Response}
case <-timer.C: // Timeout reached case <-timer.C: // Timeout reached
waitcancel() waitcancel()
return util.JSONResponse{Code: http.StatusOK, JSON: syncData} return util.JSONResponse{Code: http.StatusOK, JSON: syncReq.Response}
case <-rp.pduStream.NotifyAfter(waitctx, syncReq.Since.PDUPosition): case <-rp.pduStream.NotifyAfter(waitctx, syncReq.Since.PDUPosition):
case <-rp.typingStream.NotifyAfter(waitctx, syncReq.Since.TypingPosition): case <-rp.typingStream.NotifyAfter(waitctx, syncReq.Since.TypingPosition):