Skip to content

Commit

Permalink
fix: remove parallel file upload (causing issues)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsach64 committed Dec 9, 2024
1 parent 950a921 commit f93f5c2
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"sync"

"github.com/charmbracelet/log"
"golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -188,30 +187,25 @@ func uploadFile(sshC *ssh.Client, path string, worker server.Worker) error {
}

// Worker node ip and port
var wg sync.WaitGroup
for _, w := range otherWorkers {
if w.Ip == worker.Ip {
continue
}
wg.Add(1)
go func(ip string, port int) {
wip := fmt.Sprintf("%s:%d", ip, port)
c := client.NewClient(w.SftpUser, w.SftpPass)
// Connect to sftp server i.e worker node
sftpClient, err := c.ConnectToServer(wip)
if err != nil {
log.Fatal("Could not connect to worker node", "err", err)
}
err = client.Upload(sftpClient, path)
wip := fmt.Sprintf("%s:%d", w.Ip, w.Port)
c := client.NewClient(w.SftpUser, w.SftpPass)
// Connect to sftp server i.e worker node
sftpClient, err := c.ConnectToServer(wip)
if err != nil {
log.Fatal("Could not connect to worker node", "err", err)
}
err = client.Upload(sftpClient, path)

if err != nil {
log.Fatalf("Cannot upload file to worker node %s at because %s", wip, err)
}
log.Info("Successfully Uploaded", "file", path)
sftpClient.Close()
}(w.Ip, w.Port)
if err != nil {
log.Fatalf("Cannot upload file to worker node %s at because %s", wip, err)
}
log.Info("Successfully Uploaded", "file", path)
sftpClient.Close()
}
wg.Wait()

success, reply, err = sshC.SendRequest("finish-file-upload", true, fileInfoDat)
if err != nil {
Expand Down

0 comments on commit f93f5c2

Please sign in to comment.