Skip to content

bugfix: properly ending any thread and not generating seg fault when stopping smf process

Raphael Defosseux requested to merge fix-threads-end into develop

After Robert and Sagar told me about segmentation faults from SMF, I spent a few hours investigating and fixing

Issue 1 : properly stopping the udp_read_loop

recvfrom is a blocking call (at least in this usage) and closing the socket is not enough and wrong.

See https://linux.die.net/man/2/recvfrom and https://linux.die.net/man/2/shutdown

--> @schmidtr : That was the issue on avra and cacofonix

Issue 2 : deallocating itti_inst prematurely

itti_inst is used in a lot of our code without any nullptr check. So deallocating before the smf_app_inst causes random segmentation faults (due to some race conditions).

--> @arora : I think it is what you see on a non-5.15 kernel Ubuntu22 host

Issue 3 : making sure itti timer thread is finished before deallocating

with timer_thread.detach(); we have no control of when the thread ends.

with timer_thread.join(); then we really wait for it to be finished.

That is the most controversial fix --> it takes 2 to 3 seconds for the timer thread to be re-activated.

If you have a better idea, you're welcome.

Merge request reports