Skip to content

Commit

Permalink
fix getID will cause endless loop when noFreeID
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolocusta committed May 16, 2020
1 parent 4c98a23 commit 70d0d6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion messageids.go
Expand Up @@ -76,7 +76,7 @@ func (mids *messageIds) claimID(token tokenCompletor, id uint16) {
func (mids *messageIds) getID(t tokenCompletor) uint16 {
mids.Lock()
defer mids.Unlock()
for i := midMin; i <= midMax; i++ {
for i := midMin; i <= midMax && i != 0; i++ {
if _, ok := mids.index[i]; !ok {
mids.index[i] = t
return i
Expand Down
5 changes: 5 additions & 0 deletions unit_messageids_test.go
Expand Up @@ -71,4 +71,9 @@ func Test_noFreeID(t *testing.T) {
if mid != 0 {
t.Errorf("shouldn't be any mids left")
}

mid = mids.getID(&d)
if mid != 0 {
t.Errorf("shouldn't be any mids left")
}
}

0 comments on commit 70d0d6c

Please sign in to comment.