From 653e7dc21fe3dacc1e99a94b89c16870b8fb2de9 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 7 Oct 2017 18:50:57 +0200 Subject: [PATCH 1/2] Fix initial / fullSync request the initial/fullSync request sometimes crashed as the timout triggered before it finished. Compare Synpase which got the same if: https://github.com/matrix-org/synapse/blob/b23cb8fba8c783bf7a267bfbe33b50e010f17787/synapse/handlers/sync.py#L192 --- .../matrix-org/dendrite/syncapi/sync/requestpool.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go b/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go index 1067c98b1..3f3eacdef 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go +++ b/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go @@ -66,7 +66,9 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype // Whichever returns first is the one we will serve back to the client. timeoutChan := make(chan struct{}) timer := time.AfterFunc(syncReq.timeout, func() { - close(timeoutChan) // signal that the timeout has expired + if syncReq.timeout != 0 && syncReq.since != types.StreamPosition(0) && !syncReq.wantFullState { + close(timeoutChan) // signal that the timeout has expired + } }) done := make(chan util.JSONResponse) @@ -75,7 +77,9 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype // We stop the timer BEFORE calculating the response so the cpu work // done to calculate the response is not timed. This stops us from // doing lots of work then timing out and sending back an empty response. - timer.Stop() + if syncReq.timeout != 0 && syncReq.since != types.StreamPosition(0) && !syncReq.wantFullState { + timer.Stop() + } syncData, err := rp.currentSyncForUser(*syncReq, currentPos) var res util.JSONResponse if err != nil { From 15a4ed03335e89922ef02b6e492169d2272f88a2 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 7 Oct 2017 19:05:41 +0200 Subject: [PATCH 2/2] Fix timer never being stopped Even on a full request the timer needs to be stopped if it didn't stop yet --- .../matrix-org/dendrite/syncapi/sync/requestpool.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go b/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go index 3f3eacdef..bc5db42ed 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go +++ b/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go @@ -77,9 +77,7 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype // We stop the timer BEFORE calculating the response so the cpu work // done to calculate the response is not timed. This stops us from // doing lots of work then timing out and sending back an empty response. - if syncReq.timeout != 0 && syncReq.since != types.StreamPosition(0) && !syncReq.wantFullState { - timer.Stop() - } + timer.Stop() syncData, err := rp.currentSyncForUser(*syncReq, currentPos) var res util.JSONResponse if err != nil {