Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetworkEvents: NetworkEvents::removeEvent crashes when multiple event handlers are present #10316

Closed
1 task done
LeeLeahy2 opened this issue Sep 10, 2024 · 0 comments · Fixed by #10321 or #10337
Closed
1 task done
Labels
Status: In Progress Issue is in progress
Milestone

Comments

@LeeLeahy2
Copy link
Contributor

Board

All

Device Description

ESP32 WROVER-IE module

Hardware Configuration

No

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

Linux

Flash frequency

80 MHz

PSRAM enabled

yes

Upload speed

921600

Description

System crashes during call to NetworkEvents::removeEvent

Sketch

// bug-NetworkEvents-removeEvent.ino

#define wifiSSID        "Your_WiFi_SSID"
#define wifiPassword    "Your_WiFi_Password"

#include <WiFi.h>

bool RTK_CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC = false;

//----------------------------------------
// System initialization
void setup()
{
    Serial.begin(115200);
    Serial.println();
    Serial.println("bug-NetworkEvents-removeEvent.ino");

    // Listen for wifi events
    Serial.printf("Registering callback handler: %p\r\n", (void *)wifiEvent);
    Network.onEvent(wifiEvent);
    Network.onEvent(wifiEvent);
    Network.onEvent(wifiEvent);
    Network.onEvent(wifiEvent);

    // Start displaying the events
    Serial.println("==================== Receiving 4 events / actual event ====================");

    // Start WiFi
    WiFi.begin(wifiSSID, wifiPassword);
}

//----------------------------------------
// Main loop
void loop()
{
    static bool eventRemoved;
    static uint32_t lastTimeMillis;
    static bool wifiState;

    uint32_t currentMillis = millis();
    if ((currentMillis - lastTimeMillis) >= (10 * 1000))
    {
        lastTimeMillis = currentMillis;

        // Toggle the Wifi state
        wifiState ^= 1;
        if (wifiState)
        {
            Serial.println("---------- WiFi.disconnect ----------");
            WiFi.disconnect(true);
        }
        else
        {
            Serial.println("---------- WiFi.begin ----------");
            WiFi.begin(wifiSSID, wifiPassword);
        }
    }
    if ((!eventRemoved) && (currentMillis >= (60 * 1000)))
    {
        // Removing the WiFi event handler
        // This should remove them all!!!!!!
        Network.removeEvent(wifiEvent);
        eventRemoved = true;
        Serial.println("==================== Removed all the WiFi Event Handlers ====================");
        Serial.println("==================== No Event Output Should Be Displayed ====================");
    }
}

//----------------------------------------
void wifiEvent(arduino_event_id_t event, arduino_event_info_t info)
{
    char ssid[sizeof(info.wifi_sta_connected.ssid) + 1];
    IPAddress ipAddress;

    // Handle the event
    switch (event)
    {
    default:
        Serial.printf("ERROR: Unknown WiFi event: %d\r\n", event);
        break;

    case ARDUINO_EVENT_WIFI_OFF:
        Serial.println("WiFi Off");
        break;

    case ARDUINO_EVENT_WIFI_READY:
        Serial.println("WiFi Ready");
        break;

    case ARDUINO_EVENT_WIFI_SCAN_DONE:
        Serial.println("WiFi Scan Done");
        // wifi_event_sta_scan_done_t info.wifi_scan_done;
        break;

    case ARDUINO_EVENT_WIFI_STA_START:
        Serial.println("WiFi STA Started");
        break;

    case ARDUINO_EVENT_WIFI_STA_STOP:
        Serial.println("WiFi STA Stopped");
        break;

    case ARDUINO_EVENT_WIFI_STA_CONNECTED:
        memcpy(ssid, info.wifi_sta_connected.ssid, info.wifi_sta_connected.ssid_len);
        ssid[info.wifi_sta_connected.ssid_len] = 0;
        Serial.printf("WiFi STA connected to %s\r\n", ssid);
        break;

    case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
        memcpy(ssid, info.wifi_sta_disconnected.ssid, info.wifi_sta_disconnected.ssid_len);
        ssid[info.wifi_sta_disconnected.ssid_len] = 0;
        Serial.printf("WiFi STA disconnected from %s\r\n", ssid);
        // wifi_event_sta_disconnected_t info.wifi_sta_disconnected;
        break;

    case ARDUINO_EVENT_WIFI_STA_AUTHMODE_CHANGE:
        Serial.println("WiFi STA Auth Mode Changed");
        // wifi_event_sta_authmode_change_t info.wifi_sta_authmode_change;
        break;

    case ARDUINO_EVENT_WIFI_STA_GOT_IP:
        ipAddress = WiFi.localIP();
        Serial.print("WiFi STA Got IPv4: ");
        Serial.println(ipAddress);
        break;

    case ARDUINO_EVENT_WIFI_STA_GOT_IP6:
        Serial.print("WiFi STA Got IPv6: ");
        Serial.println(ipAddress);
        break;

    case ARDUINO_EVENT_WIFI_STA_LOST_IP:
        Serial.println("WiFi STA Lost IP");
        break;
    }
}

Debug Message

Enter the backtrace:
0x400d43f9:0x3ffb21d0 0x400d2cf1:0x3ffb2250 0x400d7894:0x3ffb2290

    PC        Stack Ptr   Symbol
----------   ----------   --------------------
0x400d7894   0x3ffb2290   loopTaskP
0x400d2cf1   0x3ffb2250   loop
0x400d43f9   0x3ffb21d0   NetworkEvents11removeEventESt8functionIFv18arduino_event_id_t20arduino_event_info_tEES1

Actual bug in getStdFunctionAddress

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@LeeLeahy2 LeeLeahy2 added the Status: Awaiting triage Issue is waiting for triage label Sep 10, 2024
@LeeLeahy2 LeeLeahy2 changed the title NetworkEvent: Skips event callbacks during removeEvent calls NetworkEvents: NetworkEvents::removeEvent crashes when multiple event handlers are present Sep 10, 2024
@VojtechBartoska VojtechBartoska added Status: In Progress Issue is in progress and removed Status: Awaiting triage Issue is waiting for triage labels Sep 10, 2024
@VojtechBartoska VojtechBartoska added this to the 3.0.5 milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: In Progress Issue is in progress
Projects
None yet
2 participants