Hi George,

OK, thanks for confirming. It looks like the same issue would occur for GET
requests as well - if `oc_do_get` is interrupted (before the request is
dispatched, and another thread begins building a new root object).

We'll make sure that our application logic protects against this. Thanks!



On Fri, Jun 5, 2020 at 2:18 AM Nash, George <[email protected]> wrote:

> If you have a situation that two threads may call oc_init_post then you
> must prevent both threads calling oc_init_post at the same time.  You must
> add a mutex or some other similar guard before calling oc_init_post and
> then you can release it after calling oc_do_post.  The same is true for
> oc_init_put and oc_do_put.
>
>
>
> George Nash
>
>
>
> *From:* [email protected] <[email protected]> *On
> Behalf Of *[email protected]
> *Sent:* Wednesday, June 3, 2020 11:00 PM
> *To:* [email protected]
> *Subject:* [dev] Protecting against concurrent requests
>
>
>
> I'm particularly interested in how the following scenario is prevented:
>
> 1. Code from one thread ("A") in the application calls
> `prepare_coap_request` (which in turn, calls `oc_rep_new`, resetting the
> current CBOR encoder state). For example, this might happen by someone
> calling `oc_init_post`.
> 2. Thread "A" sees a 'success' from `oc_init_post`, and calls
> `oc_rep_begin_root_object` and begins building a request body
> 3. Thread "A" is interrupted by higher priority thread "B" which calls
> `oc_init_post`.
> 4. Thread "B" completes and sends request
> 5. Control is returned to thread "A", which continues trying to build a
> request body, but the data is now meaningless (since the state of
> `g_encoder` and `root_map` in `oc_rep.h` have been modified
>
> Looking over the example apps, most seem to provide protection against
> this by ensuring that requests are not created in interrupts, and/or
> requests are sent via a menu driven interface. Are there further safeguards
> against this concurrency issue, is it actually a nonissue, or am I
> misunderstanding something here?
>
> 
>


-- 

Joshua Milburn, P.E. | Senior Embedded Systems Engineer

+1 (724) 612 7788 | Skype: jjmilburn

Subscribe <https://bit.ly/2YvJWMa> to Angaza’s newsletter
Twitter <https://bit.ly/3aWwLGG> | Facebook <https://bit.ly/3bXHouj> |
LinkedIn <https://bit.ly/3d4MCEB> | YouTube
<https://bit.ly/3d7rtd7> <https://bit.ly/2VTrTOh>

-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#10389): 
https://iotivity.groups.io/g/iotivity-dev/message/10389
Mute This Topic: https://groups.io/mt/74666318/21656
Group Owner: [email protected]
Unsubscribe: https://iotivity.groups.io/g/iotivity-dev/unsub  
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to