Alexander Shorin created COUCHDB-2961:
-----------------------------------------

             Summary: Let heartbeat work together with timeout for changes feed
                 Key: COUCHDB-2961
                 URL: https://issues.apache.org/jira/browse/COUCHDB-2961
             Project: CouchDB
          Issue Type: Improvement
          Components: HTTP Interface
            Reporter: Alexander Shorin


What do we have now.

Changes feeds accepts two query parameters: heartbeat and timeout. The 
heartbeat defines interval of sending heartbeat events (the {{\n}} for 
continuous and longpoll feeds, special event for eventsource one). The timeout 
defines the max time to wait for the changes and if nothing happened, CouchDB 
terminates the feed.

When you specify heartbeat with timeout together, say 
{{http://localhost:5984/db/_changes?heartbeat=1000&timeout=5000&feed=continuous}}
 I guess everyone would expect that we want to receive heartbeats every 1 
second and terminate the feed after 5 seconds of inactivity. However, timeout 
parameter will get ignored and we'll receive heartbeat every second forever.

How it should work:

Assume we want to listen continuous changes feed, receive heartbeats every 3 
seconds and terminate the feed after 10 seconds of inactivity. Then the request 
will be sort of:
{code}
http://localhost:5984/db/_changes?feed=continuous&timeout=10000&heartbeat=3000
{code}

And our expected communication:
{code}
- - C - - - H - - - H - C - - - H - - - H - - - H - T
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 
0                   1                   2            

Legend:
C - change event
H - heartbeat
T - termination
{code}

So what we need is to not reset timeout timer by sending heartbeats, but do 
that by sending real document changes.

Actually, current implementation swallow timeout parameter, replacing it with 
heartbeat value and replaces callback that stops the feed with the one that 
generates heartbeats. The fix should be trivial.

To preserve backward compatibility we may use default timeout as infinity (the 
code already supports that) if only heartbeat was explicitly specified.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to