mirror of
https://github.com/hashicorp/packer.git
synced 2026-10-04 21:53:18 -04:00
packer/rpc: don't use stream ID zero [GH-738]
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user