|
27 | 27 | handle_design_info_req/3, |
28 | 28 | parse_copy_destination_header/1, |
29 | 29 | parse_changes_query/2, |
30 | | - handle_changes_req/4 |
| 30 | + handle_changes_req/4, |
| 31 | + decrement_clients_requesting_changes_on_exit/0 |
31 | 32 | ]). |
32 | 33 |
|
33 | 34 | -import( |
@@ -189,13 +190,8 @@ handle_changes_req1(Req, Db, ChangesArgs, ChangesFun) -> |
189 | 190 | couch_stats:increment_counter( |
190 | 191 | [couchdb, httpd, clients_requesting_changes] |
191 | 192 | ), |
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). |
199 | 195 |
|
200 | 196 | handle_compact_req(#httpd{method = 'POST'} = Req, Db) -> |
201 | 197 | case Req#httpd.path_parts of |
@@ -1419,3 +1415,13 @@ validate_attachment_name(Name) -> |
1419 | 1415 | true -> Name; |
1420 | 1416 | false -> throw({bad_request, <<"Attachment name is not UTF-8 encoded">>}) |
1421 | 1417 | 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