Commit 97729e98 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: Properly close net.conn when remote process ends

parent 1745d4e8
...@@ -153,12 +153,14 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface ...@@ -153,12 +153,14 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
var cmd packer.RemoteCmd var cmd packer.RemoteCmd
cmd.Command = args.Command cmd.Command = args.Command
toClose := make([]net.Conn, 0)
if args.StdinAddress != "" { if args.StdinAddress != "" {
stdinC, err := net.Dial("tcp", args.StdinAddress) stdinC, err := net.Dial("tcp", args.StdinAddress)
if err != nil { if err != nil {
return err return err
} }
toClose = append(toClose, stdinC)
cmd.Stdin = stdinC cmd.Stdin = stdinC
} }
...@@ -168,6 +170,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface ...@@ -168,6 +170,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
return err return err
} }
toClose = append(toClose, stdoutC)
cmd.Stdout = stdoutC cmd.Stdout = stdoutC
} }
...@@ -177,6 +180,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface ...@@ -177,6 +180,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
return err return err
} }
toClose = append(toClose, stderrC)
cmd.Stderr = stderrC cmd.Stderr = stderrC
} }
...@@ -196,6 +200,9 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface ...@@ -196,6 +200,9 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
// exit. When it does, report it back to caller... // exit. When it does, report it back to caller...
go func() { go func() {
defer responseC.Close() defer responseC.Close()
for _, conn := range toClose {
defer conn.Close()
}
for !cmd.Exited { for !cmd.Exited {
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment