Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions server/container_portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ func (s StreamService) PortForward(ctx context.Context, podSandboxID string, por
ctx, span := log.StartSpan(ctx)
defer span.End()

// if we error in this function before Copying all of the content out of the stream,
// this stream will eventually get full, which causes leakages and can eventually brick CRI-O
// Drain the stream to prevent failure to close the connection and memory leakage.
// ref https://bugzilla.redhat.com/show_bug.cgi?id=1798193
emptyStreamOnError := true
// ref https://issues.redhat.com/browse/OCPBUGS-30978
defer func() {
if emptyStreamOnError && stream != nil {
go func() {
_, copyError := pools.Copy(io.Discard, stream)
log.Errorf(ctx, "Error closing port forward stream after other error: %v", copyError)
}()
if stream == nil {
return
}
go func() {
if _, err := pools.Copy(io.Discard, stream); err != nil {
log.Errorf(ctx, "Unable to drain the stream data: %v", err)
}
}()
}()

sandboxID, err := s.runtimeServer.PodIDIndex().Get(podSandboxID)
Expand All @@ -59,8 +60,5 @@ func (s StreamService) PortForward(ctx context.Context, podSandboxID string, por
)
}

// defer responsibility of emptying stream to PortForwardContainer
emptyStreamOnError = false

return s.runtimeServer.Runtime().PortForwardContainer(ctx, sb.InfraContainer(), netNsPath, port, stream)
}