Commit 90192935 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: don't use stream ID zero [GH-738]

parent 551b3c37
...@@ -189,6 +189,12 @@ func (m *MuxConn) NextId() uint32 { ...@@ -189,6 +189,12 @@ func (m *MuxConn) NextId() uint32 {
m.muAccept.Lock() m.muAccept.Lock()
defer m.muAccept.Unlock() defer m.muAccept.Unlock()
// We never use stream ID 0 because 0 is the zero value of a uint32
// and we want to reserve that for "not in use"
if m.curId == 0 {
m.curId = 1
}
for { for {
result := m.curId result := m.curId
m.curId += 1 m.curId += 1
......
...@@ -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 != 1 { if a != 1 || b != 2 {
t.Fatalf("IDs should increment") t.Fatalf("IDs should increment")
} }
a = server.NextId() a = server.NextId()
b = server.NextId() b = server.NextId()
if a != 0 || b != 1 { if a != 1 || b != 2 {
t.Fatalf("IDs should increment: %d %d", a, b) t.Fatalf("IDs should increment: %d %d", a, b)
} }
} }
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