Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 314504 - Attach to process launch leaks file descriptors
Summary: Attach to process launch leaks file descriptors
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug (show other bugs)
Version: 7.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: James Blackburn CLA
QA Contact: Ken Ryall CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-26 12:32 EDT by James Blackburn CLA
Modified: 2010-05-27 09:21 EDT (History)
2 users (show)

See Also:
marc.khouzam: review+


Attachments
file descriptor leak (78.72 KB, text/plain)
2010-05-26 12:32 EDT, James Blackburn CLA
no flags Details
proposed patch (2.34 KB, patch)
2010-05-26 15:29 EDT, James Blackburn CLA
jamesblackburn+eclipse: iplog-
Details | Diff
patch 2 (8.34 KB, patch)
2010-05-27 05:59 EDT, James Blackburn CLA
jamesblackburn+eclipse: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Blackburn CLA 2010-05-26 12:32:26 EDT
Created attachment 170038 [details]
file descriptor leak

It looks like the attack to process launch is leaking file descriptors which can make Eclipse unusable.

The attachment shows ls -l of the /proc/<java_pid>/fd. It shows filedescriptors still open to elsewhere in the proc tree. 

I had previously used the DSF attach to process launcher, so I'm guessing it's this that's looking at cmdline.
Comment 1 Marc Khouzam CLA 2010-05-26 14:28:00 EDT
What are the steps to do this?
When I try an DSF-GDB attach on a Linux 32, I just get

> ls -l /proc/10933/fd/
total 3
lrwx------ 1 lmckhou lmc_x 64 2010-05-26 14:26 0 -> /dev/pts/1
lrwx------ 1 lmckhou lmc_x 64 2010-05-26 14:26 1 -> /dev/pts/1
lrwx------ 1 lmckhou lmc_x 64 2010-05-26 14:26 2 -> /dev/pts/1
Comment 2 James Blackburn CLA 2010-05-26 14:45:05 EDT
I get this just starting an attach launch.

These issues tend to be very JVM dependent. While file descriptors are closed during garbage collection, as garbage collection is triggered by memory pressure the clean-up can be infinitely delayed. I'm guessing whatever in the attach dialog opens cmdline doesn't explicitly close the input stream. 

I can dig a bit deeper; the fix is usually trivial.
Comment 3 James Blackburn CLA 2010-05-26 15:29:18 EDT
Created attachment 170078 [details]
proposed patch

ProcessList never closes the FileReader which leaks file descriptors. 
Simple fix attached, will give it a go tomorrow when I'm back on Linux.
Comment 4 Marc Khouzam CLA 2010-05-26 21:06:49 EDT
Wow, that's a old bug.
There is a similar class in the win32 plugin which creates an InputStreamReader.  Should that one also call close()?
Comment 5 James Blackburn CLA 2010-05-27 05:59:18 EDT
Created attachment 170158 [details]
patch 2 

(In reply to comment #4)
> Wow, that's a old bug.
> There is a similar class in the win32 plugin which creates an
> InputStreamReader.  Should that one also call close()?

Yes, they all should.  It's much less bad here though, as we're only leaking one process worth of filedescriptors (per query), rather than one file descriptor for every process on the system.

I did some tracing through DSF (so many layers!) and it looks like it only falls back to these core methods when GDB doesn't list the processes (GDBProcesses_7_0#getRunningProcesses).  So this issue is most observable using CDI.

I've been through all the ProcessLists and ensure that filedescriptors and close()d and processes destroy()d.  I think it's pretty straightforward, but do review and shout if you see anything untoward!
Comment 6 James Blackburn CLA 2010-05-27 06:03:00 EDT
Committed. Marc if you could give it a look over, that would be appreciated.
Comment 8 Marc Khouzam CLA 2010-05-27 09:21:32 EDT
Looks good