Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corner case causes NextPacketID to never exit #168

Closed
thedevop opened this issue Feb 10, 2023 · 1 comment
Closed

Corner case causes NextPacketID to never exit #168

thedevop opened this issue Feb 10, 2023 · 1 comment
Assignees

Comments

@thedevop
Copy link
Collaborator

thedevop commented Feb 10, 2023

Step to reproduce:

  • Call NextPacketID, current cl.State.packetID = 65534, inflight contains 1 to 65534, it successfully obtain 65535
  • Call NextPacketID again, current cl.State.packetID = 65535, inflight contains 1 to 65535, it will never exit the loop

https://github.com/mochi-co/mqtt/blob/bb54cc68e67d43e1397286594541d77330b2910b/clients.go#L255-L256
If current value of cl.State.packetID is 65535, then i = 65535, started = 65536. Once it enters the for loop, i is set to 1 and overflowed = true. If inflight contains all 65535 messages, then the only condition it can exit the loop is:

		if overflowed && i == started {
			return 0, packets.ErrQuotaExceeded
		}

overflowed is true, but i will never reach 65536, i == started condition can never be met.

Here is an example in Go Playground, with the following condition removed.

   	if _, ok := cl.State.Inflight.Get(uint16(i)); !ok {
   		break
   	}
@thedevop thedevop changed the title Corner case cause NextPacketID never exit Corner case causes NextPacketID to never exit Feb 10, 2023
@mochi-co mochi-co self-assigned this Feb 10, 2023
@thedevop
Copy link
Collaborator Author

Resolved in #169. Thanks @mochi-co.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants