This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/CC2640R2F: Race condition between pairing callback and read attribute callback

Part Number: CC2640R2F

Tool/software: TI-RTOS

Hi,

I'm developing a custom application based on the Simple Peripheral example provided in "simplelink_cc2640r2_sdk_1_50_00_58" and I have a requirement that when pairing has successfully completed, a characteristic value is updated.  If the client performs a read request immediately after successful pairing I'm finding that approximately 30% of the time the value is not being updated.  Using breakpoints in the pair callback and the read attribute callback I'm observing what seems to be a race condition between the two callbacks, and on the occasions where it would fail the read attribute callback is being called before the pair callback even though my sniffer is showing that pairing occurs before any read request.  If I add a 5ms delay between the successful completion of pairing and the read request I can't reproduce the issue.

Due to the confidential nature of the project I am unable to share code or sniffer logs so I tried it with the simple peripheral project with one modification: that when pairing succeeds the SIMPLEPROFILE_CHAR2 characteristic value is incremented and I'm seeing exactly the same issue. 

I attach the modified simple peripheral project and a sniffer log showing the following steps repeated 7 times:

  1. Connect
  2. Read the SIMPLEPROFILE_CHAR2 characteristic
  3. Pair
  4. Read the SIMPLEPROFILE_CHAR2 characteristic
  5. Disconnect

We see that the first two attempts show the value is unchanged between the two reads.  The third attempt behaves as expected, as does the 7th but those in between do not.  What's interesting about the failing cases is that by the time we connect the next time and perform the read request the value has indeed incremented.

Are there some constraints on the timing of pairing requests and read requests or indeed any other Bluetooth operations?  Am I missing something?

https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/538/RaceCondition.7z

  • Hi,

    I can see you are setting parameter at GAPBOND_PAIRING_STATE_BOND_SAVED state.
    In your use case, you can move this one to GAPBOND_PAIRING_STATE_COMPLETE as BOND Save also invoke SNV write which takes time.

    In your log, the pairing finished at Frame 766 and the read is then performed at Frame 768 which the application might have not received the STACK saying bond info is saved.

    Also the time it take till application to get the event is not deterministic. The software overhead and the air traffic will play some part of it. This is not really a race condition as the STACK is still doing the correct thing.

    Can you try to move the SimpleProfile_SetParameter to GAPBOND_PAIRING_STATE_COMPLETE?
  • Hi Christin,

    That explanation certainly made a lot of sense, however I have tried what you suggested and I'm seeing the same issue.  Is it possible to identify where any delay in calling the callback might be coming from?

    https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/538/Race-Condition-2.7z

  • Hi,

    Sorry for the delayed response.

    As stated the time it take till application to get the event is not deterministic. The software overhead and the air traffic will play some part of it.
    Therefore there is no method to identify the where it comes from as if there has been lots of data re-transmission due to interference, it would behave differently.

    I would suggest to add delay to make sure that this condition is covered.