Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-2961

Let heartbeat work together with timeout for changes feed

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • None
    • None
    • HTTP Interface
    • None

    Description

      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:

      http://localhost:5984/db/_changes?feed=continuous&timeout=10000&heartbeat=3000
      

      And our expected communication:

      - - 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
      

      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.

      Attachments

        Activity

          People

            kxepal Alexander Shorin
            kxepal Alexander Shorin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: