couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [01/12] couch commit: updated refs/heads/2938-fix-5986-filtered-changes to 9171d5a [Forced Update!]
Date Thu, 25 Feb 2016 20:03:03 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/2938-fix-5986-filtered-changes de509a6b1 -> 9171d5a8f (forced update)

Send a real EventSource event for heartbeat

Bring back 845bf7529a3bc565d6446a7fa6cc5fd1a140653e

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/2938-fix-5986-filtered-changes
Commit: 11896807f1d27eee8789cee36bdf2c38ede42916
Parents: 010704a
Author: Damjan Georgievski <>
Authored: Fri May 2 17:04:41 2014 +0200
Committer: Damjan Georgievski <>
Committed: Tue Feb 9 18:48:30 2016 +0100

 src/couch_httpd_db.erl | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/src/couch_httpd_db.erl b/src/couch_httpd_db.erl
index 7f2ae1c..965e8fb 100644
--- a/src/couch_httpd_db.erl
+++ b/src/couch_httpd_db.erl
@@ -111,6 +111,8 @@ handle_changes_req1(Req, #db{name=DbName}=Db, ChangesArgs, ChangesFun)
                 io_lib:format("\n],\n\"last_seq\":~w}\n", [EndSeq])
+        (timeout, "eventsource") ->
+            couch_httpd:send_chunk(Resp, "event: heartbeat\ndata: \n\n");
         (timeout, _) ->
             couch_httpd:send_chunk(Resp, "\n")

View raw message