Skip to content

Commit ab33165

Browse files
committed
ensure we decrement clients_requesting_changes
ensure we decrement clients_requesting_changes even if the mochiweb process mediating the change request is killed by the client disconnect detector.
1 parent 290314a commit ab33165

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/chttpd/src/chttpd_db.erl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,8 @@ handle_changes_req1(#httpd{} = Req, Db) ->
151151
mochi = Req,
152152
threshold = Max
153153
},
154-
try
155-
fabric:changes(Db, fun changes_callback/2, Acc0, ChangesArgs)
156-
after
157-
couch_stats:decrement_counter([couchdb, httpd, clients_requesting_changes])
158-
end;
154+
couch_httpd_db:decrement_clients_requesting_changes_on_exit(),
155+
fabric:changes(Db, fun changes_callback/2, Acc0, ChangesArgs);
159156
_ ->
160157
Msg = <<"Supported `feed` types: normal, continuous, live, longpoll, eventsource">>,
161158
throw({bad_request, Msg})

src/couch/src/couch_httpd_db.erl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
handle_design_info_req/3,
2828
parse_copy_destination_header/1,
2929
parse_changes_query/2,
30-
handle_changes_req/4
30+
handle_changes_req/4,
31+
decrement_clients_requesting_changes_on_exit/0
3132
]).
3233

3334
-import(
@@ -189,13 +190,8 @@ handle_changes_req1(Req, Db, ChangesArgs, ChangesFun) ->
189190
couch_stats:increment_counter(
190191
[couchdb, httpd, clients_requesting_changes]
191192
),
192-
try
193-
WrapperFun(ChangesFun)
194-
after
195-
couch_stats:decrement_counter(
196-
[couchdb, httpd, clients_requesting_changes]
197-
)
198-
end.
193+
decrement_clients_requesting_changes_on_exit(),
194+
WrapperFun(ChangesFun).
199195

200196
handle_compact_req(#httpd{method = 'POST'} = Req, Db) ->
201197
case Req#httpd.path_parts of
@@ -1419,3 +1415,13 @@ validate_attachment_name(Name) ->
14191415
true -> Name;
14201416
false -> throw({bad_request, <<"Attachment name is not UTF-8 encoded">>})
14211417
end.
1418+
1419+
decrement_clients_requesting_changes_on_exit() ->
1420+
Self = self(),
1421+
spawn(fun() ->
1422+
MonitorRef = monitor(process, Self),
1423+
receive
1424+
{'DOWN', MonitorRef, process, Self, _Info} ->
1425+
couch_stats:decrement_counter([couchdb, httpd, clients_requesting_changes])
1426+
end
1427+
end).

0 commit comments

Comments
 (0)