Skip to content

Commit

Permalink
fix: port forward function channels (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk authored May 2, 2024
1 parent 8cd3440 commit 6ad89fb
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/k8s/k8s_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"fmt"
"io"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -259,27 +258,29 @@ func (c *Client) PortForwardPod(

stopChan := make(chan struct{}, 1)
readyChan := make(chan struct{})
defer func() {
close(stopChan)
close(readyChan)
}()

var stdout, stderr io.Writer
var stdout, stderr bytes.Buffer
// Create a new PortForwarder
pf, err := portforward.New(dialer, ports, stopChan, readyChan, stdout, stderr)
pf, err := portforward.New(dialer, ports, stopChan, readyChan, &stdout, &stderr)
if err != nil {
return ErrCreatingPortForwarder.Wrap(err)
}
if stderr != nil {
return ErrPortForwarding.WithParams(stderr)
if stderr.Len() > 0 {
return ErrPortForwarding.WithParams(stderr.String())
}
logrus.Debugf("Port forwarding from %d to %d", localPort, remotePort)
logrus.Debugf("Port forwarding stdout: %v", stdout)

errChan := make(chan error)

// Start the port forwarding
errChan := make(chan error)
defer close(errChan)
go func() {
if err := pf.ForwardPorts(); err != nil {
errChan <- err
} else {
close(errChan) // if there's no error, close the channel
}
}()

Expand Down

0 comments on commit 6ad89fb

Please sign in to comment.