From 0b698b82417b17b1098af9e64433741154345252 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 7 Jul 2025 12:32:53 +1000 Subject: [PATCH] rp2/mpnetworkport: Deregister all sys timeouts when netif is removed. When mDNS is active on a netif it registers a lot of timeouts, namely: mdns_probe_and_announce mdns_handle_tc_question mdns_multicast_probe_timeout_reset_ipv4 mdns_multicast_timeout_25ttl_reset_ipv4 mdns_multicast_timeout_reset_ipv4 mdns_send_multicast_msg_delayed_ipv4 mdns_send_unicast_msg_delayed_ipv4 mdns_multicast_probe_timeout_reset_ipv6 mdns_multicast_timeout_25ttl_reset_ipv6 mdns_multicast_timeout_reset_ipv6 mdns_send_multicast_msg_delayed_ipv6 mdns_send_unicast_msg_delayed_ipv6 These may still be active after a netif is removed, and if they are called they will find that the mDNS state pointer in the netif is NULL and they will crash. These functions could be explicitly removed using `sys_untimeout()`, but `mdns_handle_tc_question()` is static so it's not possible to access it. Instead use the new `sys_untimeout_all_with_arg()` helper to deregister all timeout callbacks when a netif is removed. Fixes issue #17621. Signed-off-by: Damien George --- ports/rp2/mpnetworkport.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/rp2/mpnetworkport.c b/ports/rp2/mpnetworkport.c index fed34be380..675552d1e5 100644 --- a/ports/rp2/mpnetworkport.c +++ b/ports/rp2/mpnetworkport.c @@ -30,6 +30,7 @@ #if MICROPY_PY_LWIP +#include "extmod/modnetwork.h" #include "shared/runtime/softtimer.h" #include "lwip/netif.h" #include "lwip/timeouts.h" @@ -183,6 +184,10 @@ static void mp_network_netif_status_cb(struct netif *netif, netif_nsc_reason_t r mp_network_soft_timer.mode = SOFT_TIMER_MODE_PERIODIC; soft_timer_reinsert(&mp_network_soft_timer, LWIP_TICK_RATE_MS); } + + if (reason == LWIP_NSC_NETIF_REMOVED) { + sys_untimeout_all_with_arg(netif); + } } #endif // MICROPY_PY_LWIP