benczebarna opened a new issue, #5495:
URL: https://github.com/apache/couchdb/issues/5495

   ## Description
   
   When making requests to CouchDB 3.0.0+, the number of occupied TCP ports 
continuously increases and doesn't properly decrease, eventually leading to 
port exhaustion.
   
   ## Steps to Reproduce
   
   1. Start CouchDB server
   2. Run this script to monitor port usage:
   ```
   const { execSync } = require('child_process');
   
   const FREQUENCY = 1000
   let previous = []
   function getCount(){
   
     const result = execSync('powershell -command "(netstat -ano)"', { 
       encoding: 'utf8',
       windowsHide: true
     });
     
     const count = result.split('\n').length
     console.log(count);
   }
   
   setInterval(() => {
       getCount()
   }, FREQUENCY);
   ```
   
   3. Run this curl script or the node script below to generate load:
   ```
   for /l %x in (1, 1, 100) do (
      curl localhost:5984
      timeout /t 1
   )
   ```
   ```
   async function sleep(ms) {
     return new Promise((resolve) => {
       setTimeout(resolve, ms);
     });
   }
   
   async function main() {
     while (1) {
       const resp = await fetch('http://localhost:5984')
       await sleep(100);
     }
   }
   
   main();
   ```
   
   
   ## Expected Behaviour
   
   CouchDB should properly reuse existing TCP connections through connection 
pooling rather than creating new connections for each request. The number of 
occupied ports should remain relatively stable even under load.
   
   ## Your Environment
   
   * CouchDB version used: 2.3.1(no issues), 3.0.0(the issue is present), 
3.3.0(the issue is present), 3.4.3(the issue is present)
   * Operating system and version: Windows 11, Windows Server 2019
   
   ## Additional Context
   
   I tried several fixes:
   
   1. Different Node.js versions
   2. Setting up connection pooling in HTTP clients
   3. Testing with curl commands
   4. Changing CouchDB config settings
   
   This problem only happens with CouchDB 3.0.0 and newer - older versions work 
fine. When the system is under load, it eventually runs out of available ports.
   
   
![Image](https://github.com/user-attachments/assets/5319328b-5085-4423-a8c6-6fee87e9f28b)
   *Caption: Port count continuously increases over time*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to