You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/05/21 18:53:24 UTC
[09/11] couch commit: updated refs/heads/master to 7ab7995
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
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/845bf752
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/845bf752
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/845bf752
Branch: refs/heads/master
Commit: 845bf7529a3bc565d6446a7fa6cc5fd1a140653e
Parents: c625e21
Author: Damjan Georgievski <gd...@gmail.com>
Authored: Fri May 2 17:04:41 2014 +0200
Committer: Robert Newson <rn...@apache.org>
Committed: Wed May 21 15:17:18 2014 +0100
----------------------------------------------------------------------
src/couch_httpd_db.erl | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/845bf752/src/couch_httpd_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_db.erl b/src/couch_httpd_db.erl
index 8c7ae77..ad8654a 100644
--- a/src/couch_httpd_db.erl
+++ b/src/couch_httpd_db.erl
@@ -105,6 +105,8 @@ handle_changes_req2(Req, Db) ->
io_lib:format("\n],\n\"last_seq\":~w}\n", [EndSeq])
),
end_json_response(Resp);
+ (timeout, "eventsource") ->
+ send_chunk(Resp, "event: heartbeat\ndata: \n\n");
(timeout, _) ->
send_chunk(Resp, "\n")
end