eclipse-threadx / netxduo

Eclipse ThreadX - NetXDuo is an advanced, industrial-grade TCP/IP network stack designed specifically for deeply embedded real-time and IoT applications
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/netx-duo/index.md
MIT License
230 stars 131 forks source link

nx_ppp_delete leaks packet pool packets through nx_ppp_receive_partial_packet #274

Open BarryAndrews opened 1 month ago

BarryAndrews commented 1 month ago

I am developing a cellular modem interface using renesas RX processor RX72N. I need to start and stop the PPP interface for each session and have followed the recommended guide.

First I stop the PPP

nx_ppp_stop(pModem->pPPP); // Now wait until the PPP thread goes to a closed state before proceeding with the delete. // This will give PPP the opportunity to properly release all packets being worked on. while (pModem->pPPP->nx_ppp_state != NX_PPP_STOPPED) { // Sleep for a tick. tx_thread_sleep(1); } Next I delete the associated IP interface

if (NX_SUCCESS == nx_ip_delete(pModem->pIP)) { if (pModem->device.DiagsOn) { LogDiagMessage("%s: IP Interface deleted", ID); } } Finally I delete the PPP interface itself

if (NX_SUCCESS == nx_ppp_delete(pModem->pPPP)) { if (pModem->device.DiagsOn) { LogDiagMessage("%s: PPP Interface deleted", ID); } }

However, I am finding that the nx_ppp_delete, does not always release the partial receive packet and I need to add this code before I delete the PPP interface to avoid my packet pool running out.

// Check if partial Rx packet needs releasing if (pModem->pPPP->nx_ppp_receive_partial_packet) { LogDiagMessage("%s: PPP Partial Receive Packet Released", ID); nx_packet_release(pModem->pPPP->nx_ppp_receive_partial_packet); pModem->pPPP->nx_ppp_receive_partial_packet = NX_NULL; } I have tried this with ip thread higher priority than ppp thread, and ip thread same priority as ppp thread. Regardless of priority, most times there is a partial receive packet allocated when I call nx_ppp_delete and this only checks the partial receive packet if the PPP isn't already stopped.