readyprompt opened a new pull request, #6198:
URL: https://github.com/apache/couchdb/pull/6198

   ## Overview
   
   Files.list() in postVisitDirectory was never closed, so each deleteAll 
leaked a directory fd. Use newDirectoryStream in a try-with-resources.  
   
   Files.list(dir) opens the directory at the OS level and hands back a Stream 
that owns that file-descriptor. That Stream is AutoCloseable and is only 
released when you close it.  But, AutoCloseable applies only to 
try-with-resources in which the compiler generates the finally { s.close(); } 
for you.  If you don’t use try-with-resources or don’t call close() yourself, 
nothing closes it.
   
   The fix is to open the DirectoryStream inside try (…), so the descriptor is 
closed the moment the block exits, leak or exception or not.
   
   We only need to know whether the directory has any entry, so we check for a 
first one and stop.
   
   ## Testing recommendations
   
   Build and run with nouveau, create a database with a nouveau index, add a 
few docs, and run one search so the index is built on disk. Note the open 
file-descriptor count of the nouveau JVM-- make sure it is the application and 
not the gradle launcher-- with ls /proc/<pid>/fd | wc -l, then POST 
/db/_nouveau_cleanup a couple hundred times and check again.
   
   ## Checklist
   
   - [x] This is my own work, I did not use AI, LLM's or similar technology
   - [x] Code is written and works correctly
   - [ ] Changes are covered by tests
   - [ ] Any new configurable parameters are documented in 
`rel/overlay/etc/default.ini`
   - [ ] Documentation changes were made in the `src/docs` folder
   - [ ] Documentation changes were backported (separated PR) to affected 
branches
   


-- 
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