Prevent nextAvailableUnicastAddress() from returning an already assigned address.
See original GitHub issueDescribe the bug
nextAvailableUnicastAddress() will return an already assigned unicast address.
A new node is added to a mesh by:
- Provisioning the device.
- Connecting to the new node and…
- (only if the connection is established) assigning and binding an app key by sending
ConfigDefaultTtlGet,ConfigNetworkTransmitSet,ConfigAppKeyAdd,ConfigModelAppBind.
If step 1. succeeds, but step 2. fails, then the library gets inconsistent with the actual mesh. The effect is that nextAvailableUnicastAddress() will return an already (at step 1.) assigned unicast address.
This happens because the library updates its internal list of nodes (BaseMeshNetwork.nodes) in response of the commands ConfigDefaultTtlGet, ConfigNetworkTransmitSet, ConfigAppKeyAdd, ConfigModelAppBind. Now if the connection to the mesh fails (step 2.), then non of those commands are sent and hence the library does not update its internal list of nodes. If a new node is now provisioned, nextAvailableUnicastAddress() will return the same address as the node that failed to connect.
To Reproduce The easiest way to reproduce this is by provisioning (and assigning app keys to) a bunch of devices in a loop. If one node fails to connect, then the following device will get the same address assigned, causing a “unicast address already in use” error to show up in logcat.
Expected behavior
nextAvailableUnicastAddress() must not return an already used unicast address. The only way to fix this is if the library updates its internal list of nodes as soon as a new node is provisioned - i.e. before connecting to the newly provisioned node.
Platform details: Happens on all Android versions.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (9 by maintainers)

Top Related StackOverflow Question
Can you please publish a snapshot version? I’d like to try it. Thanks!
@NanaDada this issue is fixed now. Please give it a test and confirm.