Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
3a415008
Commit
3a415008
authored
Dec 10, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: more robust communicator connection cleanup
parent
4c5d6170
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
13 deletions
+30
-13
packer/rpc/communicator.go
packer/rpc/communicator.go
+28
-11
packer/rpc/muxconn.go
packer/rpc/muxconn.go
+2
-2
No files found.
packer/rpc/communicator.go
View file @
3a415008
...
...
@@ -95,6 +95,7 @@ func (c *communicator) Start(cmd *packer.RemoteCmd) (err error) {
return
}
log
.
Printf
(
"[INFO] RPC client: Communicator ended with: %d"
,
finished
.
ExitStatus
)
cmd
.
SetExited
(
finished
.
ExitStatus
)
}()
...
...
@@ -146,17 +147,28 @@ func (c *communicator) Download(path string, w io.Writer) (err error) {
return
}
func
(
c
*
CommunicatorServer
)
Start
(
args
*
CommunicatorStartArgs
,
reply
*
interface
{})
(
err
err
or
)
{
func
(
c
*
CommunicatorServer
)
Start
(
args
*
CommunicatorStartArgs
,
reply
*
interface
{})
(
error
)
{
// Build the RemoteCmd on this side so that it all pipes over
// to the remote side.
var
cmd
packer
.
RemoteCmd
cmd
.
Command
=
args
.
Command
// Create a channel to signal we're done so that we can close
// our stdin/stdout/stderr streams
toClose
:=
make
([]
io
.
Closer
,
0
)
doneCh
:=
make
(
chan
struct
{})
go
func
()
{
<-
doneCh
for
_
,
conn
:=
range
toClose
{
defer
conn
.
Close
()
}
}()
if
args
.
StdinStreamId
>
0
{
conn
,
err
:=
c
.
mux
.
Dial
(
args
.
StdinStreamId
)
if
err
!=
nil
{
return
err
close
(
doneCh
)
return
NewBasicError
(
err
)
}
toClose
=
append
(
toClose
,
conn
)
...
...
@@ -166,7 +178,8 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
if
args
.
StdoutStreamId
>
0
{
conn
,
err
:=
c
.
mux
.
Dial
(
args
.
StdoutStreamId
)
if
err
!=
nil
{
return
err
close
(
doneCh
)
return
NewBasicError
(
err
)
}
toClose
=
append
(
toClose
,
conn
)
...
...
@@ -176,38 +189,42 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
if
args
.
StderrStreamId
>
0
{
conn
,
err
:=
c
.
mux
.
Dial
(
args
.
StderrStreamId
)
if
err
!=
nil
{
return
err
close
(
doneCh
)
return
NewBasicError
(
err
)
}
toClose
=
append
(
toClose
,
conn
)
cmd
.
Stderr
=
conn
}
// Connect to the response address so we can write our result to it
// when ready.
responseC
,
err
:=
c
.
mux
.
Dial
(
args
.
ResponseStreamId
)
if
err
!=
nil
{
return
err
close
(
doneCh
)
return
NewBasicError
(
err
)
}
responseWriter
:=
gob
.
NewEncoder
(
responseC
)
// Start the actual command
err
=
c
.
c
.
Start
(
&
cmd
)
if
err
!=
nil
{
close
(
doneCh
)
return
NewBasicError
(
err
)
}
// Start a goroutine to spin and wait for the process to actual
// exit. When it does, report it back to caller...
go
func
()
{
defer
close
(
doneCh
)
defer
responseC
.
Close
()
for
_
,
conn
:=
range
toClose
{
defer
conn
.
Close
()
}
cmd
.
Wait
()
log
.
Printf
(
"[INFO] RPC endpoint: Communicator ended with: %d"
,
cmd
.
ExitStatus
)
responseWriter
.
Encode
(
&
CommandFinished
{
cmd
.
ExitStatus
})
}()
return
return
nil
}
func
(
c
*
CommunicatorServer
)
Upload
(
args
*
CommunicatorUploadArgs
,
reply
*
interface
{})
(
err
error
)
{
...
...
packer/rpc/muxconn.go
View file @
3a415008
...
...
@@ -197,7 +197,7 @@ func (m *MuxConn) openStream(id uint32) (*Stream, error) {
// Create the stream object and channel where data will be sent to
dataR
,
dataW
:=
io
.
Pipe
()
writeCh
:=
make
(
chan
[]
byte
,
10
)
writeCh
:=
make
(
chan
[]
byte
,
256
)
// Set the data channel so we can write to it.
stream
:=
&
Stream
{
...
...
@@ -315,7 +315,7 @@ func (m *MuxConn) loop() {
select
{
case
stream
.
writeCh
<-
data
:
default
:
log
.
Printf
(
"[ERR] Failed to write data, buffer full: %d"
,
id
)
panic
(
fmt
.
Sprintf
(
"Failed to write data, buffer full for stream %d"
,
id
)
)
}
}
else
{
log
.
Printf
(
"[ERR] Data received for stream in state: %d"
,
stream
.
state
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment