From b4b5d5cc95e07b1bba3060297d10d83f69a38ca6 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Mon, 28 Nov 2022 14:11:44 -0800 Subject: [PATCH] Actually close connection everytime through the loop. Also, only use the client when err != nil (c could be non-nil when err == nil) --- zfs_replication_exporter.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/zfs_replication_exporter.go b/zfs_replication_exporter.go index 2feb963..528b23f 100644 --- a/zfs_replication_exporter.go +++ b/zfs_replication_exporter.go @@ -260,18 +260,17 @@ func main() { c, err := ssh.Dial("tcp", host, config) if err != nil { glog.Errorf("Error dialing %q: %v", host, err) - } - if c != nil { + } else { stats, err := fetchSnapshotStats(host, c) if err != nil { glog.Errorf("Failed to update metrics: %v", err) - c.Close() - c = nil + } else { + hss.Lock() + hss.host2Stats[host] = stats + hss.Unlock() + updateMetrics(host, stats) } - hss.Lock() - hss.host2Stats[host] = stats - hss.Unlock() - updateMetrics(host, stats) + c.Close() } time.Sleep(*refreshInterval) }