golioth / golioth-zephyr-sdk

Golioth SDK For Zephyr
https://www.golioth.io
Apache License 2.0
66 stars 19 forks source link

sockets_offload_poll_wrapper: cancel work before socket close #326

Closed mniestroj closed 1 year ago

mniestroj commented 1 year ago

So far there was a possibility that work item was in both RUNNING and QUEUED states. As a result of zsock_close() call, threaded (executed from workqueue) zsock_poll() returned. However just because work was QUEUED, sock_wrapper_poll_handler() was entered once again by workqueue thread. Subsequent work cancellation with k_work_cancel_sync() could no longer be finished, as work was waiting once again on zsock_close().

Start work cancellation using k_work_cancel() just before zsock_close() is invoked. This clears QUEUED state from work item, so sock_wrapper_poll_handler() is not reentered. After zsock_close() has returned, it is safe to call k_work_cancel_sync() to finish work cancellation and make sure that sock_wrapper_poll_handler() (hence zsock_poll()) is no longer running.

github-actions[bot] commented 1 year ago

Visit the preview URL for this PR (updated for commit 3ca1074):

https://golioth-zephyr-sdk-doxygen-dev--pr326-sock-offload-wra-rb405w07.web.app

(expires Wed, 14 Dec 2022 15:19:37 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: a389eefadf4b4b68a539327b3459dd66c142cf49