Skip to content

Missing Notification Sent While Subscribing Reproducing After Fix #130

@WkGl001

Description

@WkGl001

Hello,

I filed this issue back in November but I'm only now updating the library and trying out the fix. After undoing a workaround for the issue on my end and trying it with version 1.0.15 of the library, I'm finding that this still does reproduce.

The fix in the library involved adding parameters for a buffer and applying one to the notifications flow:

return _notifications
            .apply { if (bufferSize > 0) buffer(bufferSize, bufferOverflow) }

from ClientBleGattCharacteristic.kt starting at line 139.

I'm still seeing the first notification being missed after subscribing when it is being sent in reaction to the subscription.
The buffer was added, which I could expect to get the initial notification, but it seems like, when tryEmit is called on _notifications, that does not happen. Looking at the doc for tryEmit, I see it say:

If there are no subscribers, the buffer is not used. Instead, the most recently emitted value is simply stored into the replay cache if one was configured, displacing the older elements there, or dropped if no replay cache was configured. In any case, tryEmit returns true.

I've tried to recreate a toy example of the differences in behavior here.
This uses a MutableSharedFlow set up similarly to the one for _notifications. There's one with no replay & no applied buffer, one with no replay but it does have an applied buffer, and one which does have a replay.
When run, the output on my end shows that the first tryEmit called directly after launching a coroutine to collect does not get collected for the first two MutableSharedFlows without a replay. The one with a replay does get collected. If I uncomment the delays before the first tryEmit calls, then all values emitted get collected.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions