Remove overwrite of an already discovered characteristic #383
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using libraries based on noble-device, we've found a freezing bug that occurs during connectAndSetup() calls.
The call stack was something like
Device.prototype.connectAndSetup
NobleDevice.prototype.connectAndSetup
(create "notify" listener with self.notifyCharacteristic)
NobleDevice.prototype.discoverServicesAndCharacteristics
Noble.Peripheral.discoverAllServicesAndCharacteristics
(some events triggering)
(overwriting characteristics within
NobleDevice.prototype.discoverServicesAndCharacteristics)
(now it gets stuck waiting for "notify")
Within NobleDevice.prototype.notifyCharacteristic
(noble-device/lib/noble-device.js) the device is getting a reference
to the characteristic with
this._characteristics[serviceUuid]characteristicUuid and
waiting for that characteristic's "notify" event to call the callback.
The problem being that if the connection fails, and it goes through a
rediscover/reconnect, inside
NobleDevice.prototype.discoverServicesAndCharacteristics we can see it
overwriting the references for those characteristics
(this._characteristics[serviceUuid][characteristic.uuid] =
characteristic). So now if things run smoothly, within
NobleDevice.prototype.notifyCharacteristic it does another lookup
(:117 again) and now has a brand new reference to a newly created
characteristic. It emits "notify" on that new characteristic. But the
original call to connectAndSetup is still waiting on the old
characteristic object.