couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [43/50] documentation commit: updated refs/heads/import-master to fe7f7bf
Date Thu, 10 Jul 2014 09:47:42 GMT
Send a real EventSource event for heartbeat

The EventSource connection can get stuck (in TCP half-open state*) and there's no way
for the client to detect that. This commit changes the way heartbeat is sent, instead of
sending a newline character, it sends an empty event of type heartbeat:

    event: heartbeat

This event doesn't have an id: field, so the client will retain its latest Last-Event-ID state.

This doesn't change the expectations of clients that used EventSource till now, because they
subscribe to the 'message' event type. To get the 'heartbeat' events a client will need to
explicitly subscribe to it:

    source.addEventListener('heartbeat', function () { /* cancel a timer that would otherwise
reconnect the source */ });

* this can happen when you suspend your laptop, on flaky internet connection, ADSL reconnect,
bad wifi signals, bad routers etc. Pretty often in a typical internet usage nowadays.


Branch: refs/heads/import-master
Commit: 867bd1a08de51976da5ec3a8e19b8a6f7b9348e0
Parents: 9035fbe
Author: Damjan Georgievski <>
Authored: Fri May 2 17:04:41 2014 +0200
Committer: Klaus Trainer <>
Committed: Tue May 13 14:53:42 2014 +0200

 src/api/database/changes.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/src/api/database/changes.rst b/src/api/database/changes.rst
index fc46412..6e48f9b 100644
--- a/src/api/database/changes.rst
+++ b/src/api/database/changes.rst
@@ -398,6 +398,16 @@ parameter.
+If you set a heartbeat interval (using the ``heartbeat`` query argument), CouchDB will
+send a ``hearbeat`` event that you can subscribe to with:
+.. code-block:: javascript
+    source.addEventListener('heartbeat', function () {}, false);
+This can be monitored by the client application to restart the EventSource connection if
+needed (i.e. if the TCP connection gets stuck in a half-open state).
 .. note::
    EventSource connections are subject to cross-origin resource sharing

View raw message