Skip to content

Commit

Permalink
stop waiting on context cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
Son Roy Almerol committed Nov 11, 2024
1 parent 6b0b47e commit c708a3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 6 additions & 4 deletions cmd/windows_agent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ func (p *agentService) runLoop() {
return
}

go p.startPing()

for {
go p.startPing()
p.run()
wgDone := utils.WaitChan(&p.wg)

Expand Down Expand Up @@ -146,14 +147,15 @@ waitUrl:
}

p.wg.Add(1)

go sftp.Serve(p.ctx, &p.wg, sftpConfig, "0.0.0.0", port, driveLetter)
go func() {
sftp.Serve(p.ctx, sftpConfig, "0.0.0.0", port, driveLetter)
p.wg.Done()
}()
}
}

func (p *agentService) Stop(s service.Service) error {
p.cancel()

p.wg.Wait()
return nil
}
5 changes: 1 addition & 4 deletions internal/agent/sftp/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import (
"net"
"net/url"
"strings"
"sync"

"github.com/pkg/sftp"
"github.com/sonroyaalmerol/pbs-plus/internal/agent/snapshots"
"golang.org/x/crypto/ssh"
)

func Serve(ctx context.Context, wg *sync.WaitGroup, sftpConfig *SFTPConfig, address, port string, driveLetter string) {
defer wg.Done()

func Serve(ctx context.Context, sftpConfig *SFTPConfig, address, port string, driveLetter string) {
listenAt := fmt.Sprintf("%s:%s", address, port)
listener, err := net.Listen("tcp", listenAt)
if err != nil {
Expand Down

0 comments on commit c708a3a

Please sign in to comment.