`clients_requesting_changes` gauge not decrementing when clients disconnect in CouchDB 3.5
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- erlang
- Domain
- backend, databases, observability
Research direction
Start at the CouchDB _changes HTTP feed entry point and the stats or Prometheus output for couchdb_httpd_clients_requesting_changes; compare the increment path with disconnect handling, using abandoned_streaming_requests as evidence. Reproduce with the Docker and curl commands, then verify that active connections return to zero after clients stop while the abandonment counter remains cumulative.
Written by the indexing model from the issue text.
Description
Description
The couchdb_httpd_clients_requesting_changes gauge metric is not properly decremented when clients disconnect from the _changes feed. The metric continues to show the cumulative count of connections rather than the current active connection count.
Interestingly, the abandoned_streaming_requests counter IS being incremented when disconnections are detected, indicating that the disconnect detection logic is working, but the main gauge is not being updated.
Steps to Reproduce
Setup
-
Start CouchDB 3.5 using Docker:
docker run -d --name couchdb -p 5984:5984 \ -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password \ apache/couchdb:3.5 -
Create a test database:
curl -X PUT -u admin:password http://localhost:5984/testdb
Reproduce the issue
-
Check initial stats:
curl -s -u admin:password "http://localhost:5984/_node/_local/_stats/couchdb/httpd/clients_requesting_changes" # Expected: {"value":0,"type":"counter","desc":"number of clients for continuous _changes"} -
Start 4 continuous changes feed connections (in separate terminals or background processes):
# Terminal 1 curl -u admin:password "http://localhost:5984/testdb/_changes?feed=continuous&heartbeat=10000" # Terminal 2 curl -u admin:password "http://localhost:5984/testdb/_changes?feed=continuous&heartbeat=10000" # Terminal 3 curl -u admin:password "http://localhost:5984/testdb/_changes?feed=continuous&heartbeat=10000" # Terminal 4 curl -u admin:password "http://localhost:5984/testdb/_changes?feed=continuous&heartbeat=10000" -
Verify connections are counted:
curl -s -u admin:password "http://localhost:5984/_node/_local/_stats/couchdb/httpd/clients_requesting_changes" # Expected: {"value":4,...} -
Stop all 4 curl processes (Ctrl+C on each terminal)
-
Check stats again:
curl -s -u admin:password "http://localhost:5984/_node/_local/_stats/couchdb/httpd/clients_requesting_changes" # ACTUAL: {"value":4,...} - still shows 4! # EXPECTED: {"value":0,...} -
Check abandoned_streaming_requests:
curl -s -u admin:password "http://localhost:5984/_node/_local/_stats/couchdb/httpd/abandoned_streaming_requests" # Shows: {"value":4,...} - correctly detected 4 abandonments -
Start 4 new connections again and stop them:
# Start 4 connections, then stop them with Ctrl+C -
Check stats:
curl -s -u admin:password "http://localhost:5984/_node/_local/_stats/couchdb/httpd/clients_requesting_changes" # ACTUAL: {"value":8,...} - doubled! # EXPECTED: {"value":0,...} curl -s -u admin:password "http://localhost:5984/_node/_local/_stats/couchdb/httpd/abandoned_streaming_requests" # Shows: {"value":8,...} - correctly shows 8 total abandonments
The Prometheus endpoint correctly types this as a gauge, but the value doesn't decrease:
curl -s -u admin:password "http://localhost:5984/_node/_local/_prometheus" | grep clients_requesting_changes
# TYPE couchdb_httpd_clients_requesting_changes gauge
# couchdb_httpd_clients_requesting_changes 8
Expected Behaviour
The clients_requesting_changes metric should:
- Increment when a client starts a continuous/longpoll
_changesfeed - Decrement when the client disconnects (either normally or via TCP close)
- Always reflect the current number of active changes feed connections
Actual Behavior
- The metric increments correctly when connections start
- The metric does NOT decrement when connections end
- The
abandoned_streaming_requestscounter correctly tracks disconnections - This causes the gauge to act like a monotonic counter, accumulating over time
Your Environment
- CouchDB version used: 3.5.1
- Browser name and version: Brave 1.84.139
- Operating system and version: macOS (Darwin 24.6.0) / Docker
- Installation method: Docker (apache/couchdb:3.5 image)
Additional Context
This issue was discovered while upgrading from CouchDB 3.3.1 to 3.5.1. The metric worked correctly in 3.3.1.
The issue affects monitoring and alerting systems that rely on this metric to track the number of active changes feed consumers.
- Dominant language
- Erlang
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 5h 24m
- Merged PRs (30d)
- 10
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/couchdb
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 40/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 40/100
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 45/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
enhancement needs-triage
Difficulty 3/5 1-2 days Newbie friendliness 55/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
mksglu/context-mode#1200 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr impact:auth-provider issue-rating: 🌊 off-meta tidepool P2
Difficulty 1/5 Under an hour Newbie friendliness 80/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100