packer/rpc: muxconn can't use stream ID 0 ever

This commit is contained in:
Mitchell Hashimoto 2013-12-30 21:03:10 -08:00
parent 7177cc149f
commit ae37050e8a
2 changed files with 248 additions and 246 deletions

View File

@ -1,6 +1,8 @@
## 0.5.1 (unreleased) ## 0.5.1 (unreleased)
BUG FIXES:
* core: If a stream ID loops around, don't let it use stream ID 0 [GH-767]
## 0.5.0 (12/30/2013) ## 0.5.0 (12/30/2013)

View File

@ -191,13 +191,13 @@ func (m *MuxConn) NextId() uint32 {
m.muAccept.Lock() m.muAccept.Lock()
defer m.muAccept.Unlock() defer m.muAccept.Unlock()
for {
// We never use stream ID 0 because 0 is the zero value of a uint32 // 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" // and we want to reserve that for "not in use"
if m.curId == 0 { if m.curId == 0 {
m.curId = 1 m.curId = 1
} }
for {
result := m.curId result := m.curId
m.curId += 1 m.curId += 1
if _, ok := m.streamsAccept[result]; !ok { if _, ok := m.streamsAccept[result]; !ok {