From e861b2b6f3e110ce7703b5c50d23b23787f22450 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Mon, 12 Aug 2024 14:22:58 -0400 Subject: [PATCH] Close sshClient at the end of RunJob --- sync/client.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sync/client.go b/sync/client.go index bdea2ff..7c89207 100644 --- a/sync/client.go +++ b/sync/client.go @@ -207,7 +207,11 @@ func sftpSync(sshClient *ssh.Client, sshEntryRoot string, sshIsWindows bool, dow os.Exit(104) } defer func(sftpClient *sftp.Client) { - _ = sftpClient.Close() // error ignored; failure to close the client is not critical + err = sftpClient.Close() + if err != nil { + fmt.Println(core.AnsiError+"Sync failed - Unable to close SFTP client: ", err.Error()+core.AnsiReset) + os.Exit(104) + } }(sftpClient) // iterate over the download list @@ -453,6 +457,13 @@ func folderSync(folders []string) { func RunJob(manualSync bool) { // get SSH client to re-use throughout the sync process sshClient, sshEntryRoot, sshIsWindows := GetSSHClient(manualSync) + defer func(sshClient *ssh.Client) { + err := sshClient.Close() + if err != nil { + fmt.Println(core.AnsiError+"Sync failed - Unable to close SSH client: ", err.Error()+core.AnsiReset) + os.Exit(104) + } + }(sshClient) // fetch remote lists remoteEntryModMap, remoteFolders, deletions, serverTime, clientTime := getRemoteDataFromClient(sshClient, manualSync)