couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [1/2] couch commit: updated refs/heads/master to f3b7f5a
Date Tue, 16 Feb 2016 20:06:52 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/master 0aae568e2 -> f3b7f5a47


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

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.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/11896807
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/11896807
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/11896807

Branch: refs/heads/master
Commit: 11896807f1d27eee8789cee36bdf2c38ede42916
Parents: 010704a
Author: Damjan Georgievski <gdamjan@gmail.com>
Authored: Fri May 2 17:04:41 2014 +0200
Committer: Damjan Georgievski <gdamjan@gmail.com>
Committed: Tue Feb 9 18:48:30 2016 +0100

----------------------------------------------------------------------
 src/couch_httpd_db.erl | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/11896807/src/couch_httpd_db.erl
----------------------------------------------------------------------
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])
             ),
             couch_httpd:end_json_response(Resp);
+        (timeout, "eventsource") ->
+            couch_httpd:send_chunk(Resp, "event: heartbeat\ndata: \n\n");
         (timeout, _) ->
             couch_httpd:send_chunk(Resp, "\n")
         end


Mime
View raw message