Correctly clean up timer

This commit is contained in:
Erik Johnston 2017-10-12 09:53:29 +01:00
parent 6c98aa7666
commit 59d99dcf3c

View file

@ -79,13 +79,15 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype
// Otherwise, we wait for the notifier to tell us if something *may* have // Otherwise, we wait for the notifier to tell us if something *may* have
// happened. We loop in case it turns out that nothing did happen. // happened. We loop in case it turns out that nothing did happen.
timeoutChan := time.After(syncReq.timeout) // case of timeout=0 is handled above timer := time.NewTimer(syncReq.timeout) // case of timeout=0 is handled above
defer timer.Stop()
for { for {
select { select {
// Wait for notifier to wake us up // Wait for notifier to wake us up
case currPos = <-rp.makeNotifyChannel(*syncReq, currPos): case currPos = <-rp.makeNotifyChannel(*syncReq, currPos):
// Or for timeout to expire // Or for timeout to expire
case <-timeoutChan: case <-timer.C:
return util.JSONResponse{ return util.JSONResponse{
Code: 200, Code: 200,
JSON: types.NewResponse(syncReq.since), JSON: types.NewResponse(syncReq.since),