From f2fa845e16b99387918fbd88dcf221be1b39ae81 Mon Sep 17 00:00:00 2001 From: EYHN Date: Thu, 9 Apr 2026 21:43:11 +0800 Subject: [PATCH] fix(bridge): close stdout/stderr pipes on exec timeout to prevent stream hang (#351) --- cmd/bridge/server.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/bridge/server.go b/cmd/bridge/server.go index 164d9048..03f933a9 100644 --- a/cmd/bridge/server.go +++ b/cmd/bridge/server.go @@ -388,6 +388,17 @@ func execPipe(stream pb.ContainerService_ExecServer, firstMsg *pb.ExecInput) err return status.Errorf(codes.Internal, "start: %v", err) } + // When the context deadline fires, exec.CommandContext sends SIGKILL to the + // main process. However, child processes may still hold the stdout/stderr + // pipe file descriptors open, causing streamPipe's Read to block forever. + // Closing the pipes here unblocks those reads so the function can proceed + // to cmd.Wait and send the EXIT message back to the client. + go func() { + <-ctx.Done() + _ = stdoutPipe.Close() + _ = stderrPipe.Close() + }() + go func() { for { msg, recvErr := stream.Recv()