diff options
author | Leandro Martelli <martelli@epix.com.br> | 2020-01-02 11:42:43 +0000 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2020-01-02 15:22:31 +0100 |
commit | 492d592a69c74ed62c7b33489d38559beb20cbbc (patch) | |
tree | 92e2a641ce25610620a835aefb4430b165ad8bd7 /netboot/rtnetlink_linux.go | |
parent | 9a95b101e205d121810f3922999e1af1d39e4c43 (diff) |
Fix "conn" leaking, which eventually leads to thread exhaustion on machines with many NICs
Signed-off-by: Leandro Martelli <martelli@epix.com.br>
Diffstat (limited to 'netboot/rtnetlink_linux.go')
-rw-r--r-- | netboot/rtnetlink_linux.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/netboot/rtnetlink_linux.go b/netboot/rtnetlink_linux.go index 41f5b3e..f6886f8 100644 --- a/netboot/rtnetlink_linux.go +++ b/netboot/rtnetlink_linux.go @@ -1,6 +1,10 @@ package netboot -import "github.com/jsimonetti/rtnetlink" +import ( + "log" + + "github.com/jsimonetti/rtnetlink" +) // getOperState returns the operational state for the given interface index. func getOperState(iface int) (rtnetlink.OperationalState, error) { @@ -8,6 +12,13 @@ func getOperState(iface int) (rtnetlink.OperationalState, error) { if err != nil { return 0, err } + defer func() { + err := conn.Close() + if err != nil { + log.Printf("failed to close rtnetlink connection: %v", err) + } + }() + msg, err := conn.Link.Get(uint32(iface)) if err != nil { return 0, err |