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

This commit is contained in:
Mitchell Hashimoto 2013-12-20 22:01:38 -08:00
parent 551b3c3741
commit 901929356f
2 changed files with 8 additions and 2 deletions

View File

@ -189,6 +189,12 @@ func (m *MuxConn) NextId() uint32 {
m.muAccept.Lock()
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 {
result := m.curId
m.curId += 1

View File

@ -241,14 +241,14 @@ func TestMuxConnNextId(t *testing.T) {
a := client.NextId()
b := client.NextId()
if a != 0 || b != 1 {
if a != 1 || b != 2 {
t.Fatalf("IDs should increment")
}
a = server.NextId()
b = server.NextId()
if a != 0 || b != 1 {
if a != 1 || b != 2 {
t.Fatalf("IDs should increment: %d %d", a, b)
}
}