Skip to content
This repository has been archived by the owner on Dec 16, 2018. It is now read-only.

Commit

Permalink
Fix double-close of FD on garbage collection (rcrowley#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtharp committed Jun 24, 2016
1 parent f2f192b commit c0d4995
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions goagain.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ func Listener() (l net.Listener, err error) {
if _, err = fmt.Sscan(os.Getenv("GOAGAIN_FD"), &fd); nil != err {
return
}
l, err = net.FileListener(os.NewFile(fd, os.Getenv("GOAGAIN_NAME")))
// NewFile takes over the fd but FileListener makes its own copy. Make sure
// to clean up the former.
fdf := os.NewFile(fd, os.Getenv("GOAGAIN_NAME"))
defer fdf.Close()
l, err = net.FileListener(fdf)
if nil != err {
return
}
Expand All @@ -183,9 +187,6 @@ func Listener() (l net.Listener, err error) {
)
return
}
if err = syscall.Close(int(fd)); nil != err {
return
}
return
}

Expand Down

0 comments on commit c0d4995

Please sign in to comment.