Commit edbdee5d authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: accept/dial stream IDs are unique [GH-727]

parent 629f3eee
...@@ -17,7 +17,7 @@ type Client struct { ...@@ -17,7 +17,7 @@ type Client struct {
} }
func NewClient(rwc io.ReadWriteCloser) (*Client, error) { func NewClient(rwc io.ReadWriteCloser) (*Client, error) {
result, err := newClientWithMux(NewMuxConn(rwc, 0), 0) result, err := newClientWithMux(NewMuxConn(rwc), 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -164,7 +164,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface ...@@ -164,7 +164,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
} }
}() }()
if args.StdinStreamId > 0 { if args.StdinStreamId >= 0 {
conn, err := c.mux.Dial(args.StdinStreamId) conn, err := c.mux.Dial(args.StdinStreamId)
if err != nil { if err != nil {
close(doneCh) close(doneCh)
...@@ -175,7 +175,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface ...@@ -175,7 +175,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
cmd.Stdin = conn cmd.Stdin = conn
} }
if args.StdoutStreamId > 0 { if args.StdoutStreamId >= 0 {
conn, err := c.mux.Dial(args.StdoutStreamId) conn, err := c.mux.Dial(args.StdoutStreamId)
if err != nil { if err != nil {
close(doneCh) close(doneCh)
...@@ -186,7 +186,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface ...@@ -186,7 +186,7 @@ func (c *CommunicatorServer) Start(args *CommunicatorStartArgs, reply *interface
cmd.Stdout = conn cmd.Stdout = conn
} }
if args.StderrStreamId > 0 { if args.StderrStreamId >= 0 {
conn, err := c.mux.Dial(args.StderrStreamId) conn, err := c.mux.Dial(args.StderrStreamId)
if err != nil { if err != nil {
close(doneCh) close(doneCh)
...@@ -253,7 +253,6 @@ func (c *CommunicatorServer) Download(args *CommunicatorDownloadArgs, reply *int ...@@ -253,7 +253,6 @@ func (c *CommunicatorServer) Download(args *CommunicatorDownloadArgs, reply *int
} }
func serveSingleCopy(name string, mux *MuxConn, id uint32, dst io.Writer, src io.Reader) { func serveSingleCopy(name string, mux *MuxConn, id uint32, dst io.Writer, src io.Reader) {
log.Printf("[DEBUG] %s: Connecting to stream %d", name, id)
conn, err := mux.Accept(id) conn, err := mux.Accept(id)
if err != nil { if err != nil {
log.Printf("[ERR] '%s' accept error: %s", name, err) log.Printf("[ERR] '%s' accept error: %s", name, err)
......
This diff is collapsed.
...@@ -33,7 +33,7 @@ func testMux(t *testing.T) (client *MuxConn, server *MuxConn) { ...@@ -33,7 +33,7 @@ func testMux(t *testing.T) (client *MuxConn, server *MuxConn) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
server = NewMuxConn(conn, 1) server = NewMuxConn(conn)
}() }()
// Client side // Client side
...@@ -41,7 +41,7 @@ func testMux(t *testing.T) (client *MuxConn, server *MuxConn) { ...@@ -41,7 +41,7 @@ func testMux(t *testing.T) (client *MuxConn, server *MuxConn) {
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
client = NewMuxConn(conn, 0) client = NewMuxConn(conn)
// Wait for the server // Wait for the server
<-doneCh <-doneCh
...@@ -241,14 +241,14 @@ func TestMuxConnNextId(t *testing.T) { ...@@ -241,14 +241,14 @@ func TestMuxConnNextId(t *testing.T) {
a := client.NextId() a := client.NextId()
b := client.NextId() b := client.NextId()
if a != 0 || b != 2 { if a != 0 || b != 1 {
t.Fatalf("IDs should increment") t.Fatalf("IDs should increment")
} }
a = server.NextId() a = server.NextId()
b = server.NextId() b = server.NextId()
if a != 1 || b != 3 { if a != 0 || b != 1 {
t.Fatalf("IDs should increment: %d %d", a, b) t.Fatalf("IDs should increment: %d %d", a, b)
} }
} }
...@@ -36,7 +36,7 @@ type Server struct { ...@@ -36,7 +36,7 @@ type Server struct {
// NewServer returns a new Packer RPC server. // NewServer returns a new Packer RPC server.
func NewServer(conn io.ReadWriteCloser) *Server { func NewServer(conn io.ReadWriteCloser) *Server {
result := newServerWithMux(NewMuxConn(conn, 1), 0) result := newServerWithMux(NewMuxConn(conn), 0)
result.closeMux = true result.closeMux = true
return result return result
} }
......
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