<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nRF5 SDK for Mesh: Possible race condition in timeslot_start()?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/99699/nrf5-sdk-for-mesh-possible-race-condition-in-timeslot_start</link><description>Hello there, 
 In the course of the development of a firmware that relies on the nRF5 SDK&amp;#39;s timeslot.c I stumbled upon a possible issue in timeslot_start(): 
 Apart from the Init-Function, the value of m_current_timeslot.session_state is modified in the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 23 May 2023 10:06:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/99699/nrf5-sdk-for-mesh-possible-race-condition-in-timeslot_start" /><item><title>RE: nRF5 SDK for Mesh: Possible race condition in timeslot_start()?</title><link>https://devzone.nordicsemi.com/thread/426829?ContentTypeID=1</link><pubDate>Tue, 23 May 2023 10:06:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64cec7b6-84c5-4298-9a1d-6e5c5898b3d4</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;For your reference, our internal ticket to track the progress on this discussion is&amp;nbsp;MBTLE-4290. I will update you when I have more details from the Mesh team. But for now, I suggest that you go ahead with your prototyping and if scenario 1) turns out to be very possible, then we can come up with a workaround.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK for Mesh: Possible race condition in timeslot_start()?</title><link>https://devzone.nordicsemi.com/thread/426791?ContentTypeID=1</link><pubDate>Tue, 23 May 2023 08:30:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:396fb236-3dc3-4633-8b0d-0520dd599c9e</guid><dc:creator>m.wagner</dc:creator><description>&lt;p&gt;Okay great, thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK for Mesh: Possible race condition in timeslot_start()?</title><link>https://devzone.nordicsemi.com/thread/426776?ContentTypeID=1</link><pubDate>Tue, 23 May 2023 08:08:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe5ec01d-b49f-47cd-9532-da9e62e89e81</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Michael, Thanks for your patience and I hope that you had a some days to rest over the long weekend.&lt;/p&gt;
&lt;p&gt;I think I see the scenario&amp;nbsp;which you describe, but I would like to discuss this with the Mesh experts. The whole discussion is based on the response of &lt;span&gt;(&lt;/span&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/95384/timeslot-api-can-application-code-be-executed-between-signal-handler-and-softdevice-event-handler"&gt;Timeslot API: Can application code be executed between signal handler and Softdevice event handler?&lt;/a&gt;&lt;span&gt;),&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I do not think that Mesh timeslot handling was done expecting that the application can run between signal handler and event handler. I will create an internal ticket and have some brain storming with Mesh team before we conclude this. This might take time, but I think would yield better results including the Mesh team here.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK for Mesh: Possible race condition in timeslot_start()?</title><link>https://devzone.nordicsemi.com/thread/426030?ContentTypeID=1</link><pubDate>Wed, 17 May 2023 05:36:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6393467c-8d0f-4ed7-b61a-828bfe39c8b3</guid><dc:creator>m.wagner</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;br /&gt;&lt;br /&gt;No problem, we&amp;#39;ve got a holiday weekend as well and it is indeed not a pressing matter!&lt;br /&gt;&lt;br /&gt;Thank you for taking your time and best regards,&lt;br /&gt;-mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK for Mesh: Possible race condition in timeslot_start()?</title><link>https://devzone.nordicsemi.com/thread/425973?ContentTypeID=1</link><pubDate>Tue, 16 May 2023 17:45:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87f8b662-73fe-40eb-82f2-a3e5c7a76c3e</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hmm,&lt;/p&gt;
&lt;p&gt;Michal, I need to take a closer look at the whole state.machine one more time. Unfortunately I wont be able to do that before next week as it is holiday week in Norway after today and I already am at Home.&lt;/p&gt;
&lt;p&gt;Fortunately, we are discussing the theoretical possibilities of a race condition, so you are not blocked in your development. So I am hoping, me answering you next week about this would be OK?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK for Mesh: Possible race condition in timeslot_start()?</title><link>https://devzone.nordicsemi.com/thread/425781?ContentTypeID=1</link><pubDate>Tue, 16 May 2023 07:50:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b52733be-5b8a-43d3-a057-72f583421b31</guid><dc:creator>m.wagner</dc:creator><description>[quote userid="6207" url="~/f/nordic-q-a/99699/nrf5-sdk-for-mesh-possible-race-condition-in-timeslot_start/425777"]If the timeslot is successfully requested but not started yet, then timeslot_stop-&amp;gt;timeslot_trigger-&amp;gt;&lt;span&gt;m_current_timeslot&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;in_progress must be false since it is set to true only when application handles the START signal from the softdevice.&lt;/span&gt;[/quote]
&lt;p&gt;That is true, but m_timeslot_forced_command will get set and thus the else-clause in radio_signal_callback() will result in NRF_RADIO_SIGNAL_CALLBACK_ACTION_END being returned, leading to the scenario described in case 1.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK for Mesh: Possible race condition in timeslot_start()?</title><link>https://devzone.nordicsemi.com/thread/425777?ContentTypeID=1</link><pubDate>Tue, 16 May 2023 07:35:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8aae4c91-0ac0-44a6-854d-bbf4a4b91a26</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="m.wagner"]I think we do have a misunderstanding concerning scenario 1. By &amp;quot;timeslot not currently being served&amp;quot; I mean that the timeslot was successfully requested, but at the time of timeslot_stop() being executed, the timeslot is not currently granted due to (pending) softdevice activity (e.g. due to a connection event).&lt;br /&gt;&lt;br /&gt;We would enter the if ()-clause and thus force the timeslot to stop immediately when the START signal is handled the next time around.[/quote]
&lt;p&gt;If the timeslot is successfully requested but not started yet, then timeslot_stop-&amp;gt;timeslot_trigger-&amp;gt;&lt;span&gt;m_current_timeslot&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;in_progress must be false since it is set to true only when application handles the START signal from the softdevice. So I do not see timeslot_stop able to do anything without a proper start being handled by the application (inside&amp;nbsp;&lt;/span&gt;handle_signal_start-&amp;gt;on_ts_begin-&amp;gt;&lt;span&gt;p_timeslot&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;in_progress&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;true&lt;/span&gt;&lt;span&gt;;)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK for Mesh: Possible race condition in timeslot_start()?</title><link>https://devzone.nordicsemi.com/thread/425764?ContentTypeID=1</link><pubDate>Tue, 16 May 2023 06:00:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3156c4e-7733-48a6-91d0-5f8d5340909d</guid><dc:creator>m.wagner</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;br /&gt;Thanks for your response.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span&gt;I think we do have a misunderstanding concerning scenario 1. By &amp;quot;timeslot not currently being served&amp;quot; I mean that the timeslot was successfully requested, but at the time of timeslot_stop() being executed, the timeslot is not currently granted due to (pending) softdevice activity (e.g. due to a connection event).&lt;br /&gt;&lt;br /&gt;We would enter the if ()-clause and thus force the timeslot to stop immediately when the START signal is handled the next time around.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Re-checking &lt;span&gt;m_current_timeslot&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;session_state in scenario 2 seems like a sensible workaround, thank you.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span&gt;Thank you / best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-mike&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF5 SDK for Mesh: Possible race condition in timeslot_start()?</title><link>https://devzone.nordicsemi.com/thread/425748?ContentTypeID=1</link><pubDate>Tue, 16 May 2023 05:00:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a08c15e2-4f56-439f-ac7e-f24cd76594a2</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Michal,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;timeslot_stop would do nothing if the session is not being served. I think it also the application responsibility to keep track of states and to fence/protect the trigger of the API where ever it is not appropriate. Like you already noticed, timeslot_stop have an if condition in it that checks the session state to see if the session state is in the right state. In this scenario,&amp;nbsp;&lt;span&gt;m_current_timeslot.session_state would not be equal to STATE_RUNNING so nothing should happen here.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;This scenario seems like a possibility, in which case the application can handle&amp;nbsp; the the&amp;nbsp;&lt;span&gt;&lt;span&gt;NRF_ERROR_FORBIDDEN&amp;nbsp;error by looking at the&amp;nbsp;&lt;/span&gt;&lt;/span&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;m_current_timeslot&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;session_state again to handle the race condition before having an application panic/assert.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>