Close all inherited unnecessary file descriptor
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Object Storage (swift) |
Expired
|
Undecided
|
Unassigned |
Bug Description
In Unix and Unix like systems the child process after a fork(2) (or clone(2)) call inherits the parent process's file descriptor .
The execve(2) preserves the file descriptors as well, unless FD_CLOEXEC is set on the given fd.
Now the devstack leaking file descriptors, so you can see the fd 3 and 6 are inherited by all swift processes.
Example /proc/$pid/fd listing:
lrwx------. 1 stack stack 64 Jan 7 18:36 0 -> /dev/null
lrwx------. 1 stack stack 64 Jan 7 18:36 1 -> /dev/null
lrwx------. 1 stack stack 64 Jan 7 18:36 2 -> /dev/null
lrwx------. 1 stack stack 64 Jan 7 18:36 3 -> /dev/pts/0
lrwx------. 1 stack stack 64 Jan 7 18:36 5 -> socket:[197825]
lrwx------. 1 stack stack 64 Jan 7 18:36 6 -> /dev/pts/0
However the parent process is the primary responsible to avoid this. The service processes should make sure they do not waste fd resources as well.
The swift-init should not let their children to inherit his inherited file descriptors!
Note:
In bash you can create new inheritable fd by similar command to this:
exec 7>&1
hi Attila
I'm not clear about your understanding of "waste" :
Below is my thinking: (case about proxy process)
$/proc/39684/fd: ls -alh
dr-x------ 2 swift swift 0 Mar 13 16:06 .
dr-xr-xr-x 9 swift swift 0 Mar 12 13:14 ..
lrwx------ 1 swift swift 64 Mar 13 16:06 0 -> /dev/null
lrwx------ 1 swift swift 64 Mar 13 16:06 1 -> /dev/null
lrwx------ 1 swift swift 64 Mar 13 16:06 2 -> /dev/pts/5
lrwx------ 1 swift swift 64 Mar 13 16:06 3 -> socket:[394661]
lrwx------ 1 swift swift 64 Mar 13 16:06 4 -> socket:[394662]
lrwx------ 1 swift swift 64 Mar 13 16:06 5 -> socket:[394663]
lrwx------ 1 swift swift 64 Mar 13 16:06 6 -> socket:[394664]
lrwx------ 1 swift swift 64 Mar 13 16:06 7 -> socket:[394665]
and check all sockets available or not like that:
$cat /proc/net/tcp | grep 39466
4: 00000000:22B8 00000000:0000 0A 00000000:00000000 00:00000000 00000000 1000 0 394665 1 0000000000000000 100 0 0 10 -1
That socket is (0.0.0.0:8888, 0.0.0.0:0) which belongs to proxy process. But in /proc/39684/fd, file descriptor 3~6 is wasted?
That's your understanding?