packer/rpc: don't use stream ID zero [GH-738]
This commit is contained in:
parent
551b3c3741
commit
901929356f
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue