Skip to content

Commit

Permalink
Fixes a file descriptor leak in the process monitoring feature. The g…
Browse files Browse the repository at this point in the history
…olang garbage collector automatically closes the FD associated with os.File which is why the FD count didn't grow completely unbounded; in my testing the FD count would cyclically grow to about ~500 and then drop back down to ~5.

Close elastic#335
  • Loading branch information
andrewkroh committed Oct 26, 2015
1 parent c42da7c commit 282ebf9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file based on the
### Backward Compatibility Breaks

### Bugfixes
- Close file descriptors used to monitor processes. #337

### Added

Expand Down
3 changes: 3 additions & 0 deletions procs/procs.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func FindPidsByCmdlineGrep(prefix string, process string) ([]int, error) {
if err != nil {
return pids, fmt.Errorf("Open /proc: %s", err)
}
defer proc.Close()

names, err := proc.Readdirnames(0)
if err != nil {
Expand Down Expand Up @@ -271,6 +272,7 @@ func (proc *ProcessesWatcher) UpdateMap() {
logp.Err("Open: %s", err)
return
}
defer file.Close()
socks, err := Parse_Proc_Net_Tcp(file)
if err != nil {
logp.Err("Parse_Proc_Net_Tcp: %s", err)
Expand Down Expand Up @@ -365,6 +367,7 @@ func FindSocketsOfPid(prefix string, pid int) (inodes []int64, err error) {
if err != nil {
return []int64{}, fmt.Errorf("Open: %s", err)
}
defer procfs.Close()
names, err := procfs.Readdirnames(0)
if err != nil {
return []int64{}, fmt.Errorf("Readdirnames: %s", err)
Expand Down

0 comments on commit 282ebf9

Please sign in to comment.