close connections more reliably
This commit is contained in:
parent
407ced6405
commit
c99011b091
@ -685,13 +685,12 @@ func NodeWaitForLogMessage(ctx context.Context, runtime runtimes.Runtime, node *
|
||||
|
||||
// read the logs
|
||||
out, err := runtime.GetNodeLogs(ctx, node, since)
|
||||
if out != nil {
|
||||
defer out.Close()
|
||||
}
|
||||
if err != nil {
|
||||
if out != nil {
|
||||
out.Close()
|
||||
}
|
||||
return fmt.Errorf("Failed waiting for log message '%s' from node '%s': %w", message, node.Name, err)
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
nRead, _ := buf.ReadFrom(out)
|
||||
|
@ -309,6 +309,9 @@ func (d Docker) GetNodeLogs(ctx context.Context, node *k3d.Node, since time.Time
|
||||
// ExecInNodeGetLogs executes a command inside a node and returns the logs to the caller, e.g. to parse them
|
||||
func (d Docker) ExecInNodeGetLogs(ctx context.Context, node *k3d.Node, cmd []string) (*bufio.Reader, error) {
|
||||
resp, err := executeInNode(ctx, node, cmd)
|
||||
if resp != nil {
|
||||
defer resp.Close()
|
||||
}
|
||||
if err != nil {
|
||||
if resp != nil && resp.Reader != nil { // sometimes the exec process returns with a non-zero exit code, but we still have the logs we
|
||||
return resp.Reader, err
|
||||
@ -321,6 +324,9 @@ func (d Docker) ExecInNodeGetLogs(ctx context.Context, node *k3d.Node, cmd []str
|
||||
// ExecInNode execs a command inside a node
|
||||
func (d Docker) ExecInNode(ctx context.Context, node *k3d.Node, cmd []string) error {
|
||||
execConnection, err := executeInNode(ctx, node, cmd)
|
||||
if execConnection != nil {
|
||||
defer execConnection.Close()
|
||||
}
|
||||
if err != nil {
|
||||
if execConnection != nil && execConnection.Reader != nil {
|
||||
logs, err := ioutil.ReadAll(execConnection.Reader)
|
||||
|
@ -149,6 +149,7 @@ func (d Docker) ReadFromNode(ctx context.Context, path string, node *k3d.Node) (
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get docker client: %w", err)
|
||||
}
|
||||
defer docker.Close()
|
||||
|
||||
reader, _, err := docker.CopyFromContainer(ctx, nodeContainer.ID, path)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user