Program crash when using either ArduinoOTA or WebServer

I have an ESP32-C3-OLED board which works well when I do

  • OLED tuff (writing to the LCD screen)
  • WIFI (got IP address)
  • sensor with BME280

But when I add either ArduinoOTA or WebServer, it crashes. (stacktrace below)
I have reduced the code to a minimal reproducer:

#include <WebServer.h>
WebServer wserver(80);
void doweb() {
  Serial.println("WEB");
}
void setup() {
  Serial.begin(115200);
  Serial.print(heap_caps_get_free_size(MALLOC_CAP_8BIT));
  wserver.on("/", doweb);
  wserver.onNotFound(doweb); 
  wserver.begin();
}

static int c;
static int uptime;
void loop() {
  delay(1000);
  if (c++ > 50) {
    c = 0;
    Serial.print("ALive");
    Serial.println(uptime++);
  }
}

If I comment wserver.begin() it works.

Any help will be apreciated

17:23:57.771 -> assert failed: xQueueSemaphoreTake queue.c:1709 (( pxQueue ))
17:23:57.771 -> Core 0 register dump:
17:23:57.771 -> MEPC : 0x40384ff2 RA : 0x40384fb6 SP : 0x3fc9b080 GP : 0x3fc8e800
17:23:57.805 -> TP : 0x3fc9b330 T0 : 0x37363534 T1 : 0x7271706f T2 : 0x33323130
17:23:57.805 -> S0/FP : 0x00000001 S1 : 0x3fc9b1ed A0 : 0x3fc9b0e4 A1 : 0x3fc8f359
17:23:57.805 -> A2 : 0x00000001 A3 : 0x00000029 A4 : 0x00000001 A5 : 0x3fc92000
17:23:57.805 -> A6 : 0x7a797877 A7 : 0x76757473 S2 : 0x0000008a S3 : 0x3fc9b0d8
17:23:57.838 -> S4 : 0x3fc9b0d8 S5 : 0x3fc9b0e4 S6 : 0x00000000 S7 : 0x00000000
17:23:57.838 -> S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
17:23:57.838 -> T3 : 0x6e6d6c6b T4 : 0x6a696867 T5 : 0x66656463 T6 : 0x62613938
17:23:57.838 -> MSTATUS : 0x00001881 MTVEC : 0x40380001 MCAUSE : 0x00000002 MTVAL : 0x00000000
17:23:57.871 -> MHARTID : 0x00000000
17:23:57.871 ->

It looks like nothing in your sketch is actually wrong. From what I’ve seen, the ESP32-C3 is a bit unstable when you use the classic WebServer class (and sometimes ArduinoOTA).
The crash you’re getting:

assert failed: xQueueSemaphoreTake queue.c:1709

usually comes from inside the ESP32 core itself, not from user code.

I’m not 100% sure, but it seems to be a known issue specifically on the C3 boards, especially the OLED versions. The older WebServer implementation wasn’t really designed for the RISC-V C3.

You might want to try switching to ESPAsyncWebServer or the ESP-IDF esp_http_server those tend to be a lot more stable on the C3. Also updating to the latest ESP32 Arduino core sometimes helps.

So my guess is: your code is fine, it’s more likely a C3 WebServer bug.

Thanks for your reply. But Arduino OTA also lead to crash.
I forgot also that creating a simple TCP server lead also to crash.
Too many crash in unrelated parts, it is strange.

I use the latest esp32 libraries 3.3.3

Thanks for the details.
If WebServer, OTA and even a simple TCP server all crash, that’s almost always a C3 issue, not your code. The C3 has tighter RAM and some parts of the Arduino core (even 3.3.3) are still unstable, especially on OLED boards.

Try disabling the OLED, turning off WiFi sleep, or using core 2.0.14 many people report it’s much more stable there.

Try backing off the BOARDS espressif from 3.x to 2.0.17

Your topic does not indicate a problem with IDE 2.x and therefore has been moved to a more suitable category of the forum.

With esp32 2.0.x, it fail to use the serial so unusable.

If 2.0.x breaks serial for you, it might not be the core itself but the USB-CDC setting or the board variant definition. On some ESP32 boards the 2.0.x series defaults to USB-CDC-on-boot, and that can make the normal UART appear dead. I’m not completely sure, but disabling USB-CDC in menuconfig or switching the upload/monitor port back to the classic UART usually restores serial.

So 2.0.17 can still work, but only if the serial mode is configured correctly.

can you try with one of the examples which came with the platform package?
Which one fails?

Since it does work for many others, more info is needed. Start with the built in examples then try backing off the boards to 2.0.1x as suggested in several posts to you.

With 2.0.17 I got:

17:47:39.956 -> assert failed: tcpip_send_msg_wait_sem IDF/components/lwip/lwip/src/api/tcpip.c:455 (Invalid mbox)
17:47:39.956 -> Core 0 register dump:
17:47:39.956 -> MEPC : 0x40381c5c RA : 0x40384d96 SP : 0x3fc95780 GP : 0x3fc8ba00
17:47:39.956 -> TP : 0x3fc89064 T0 : 0x37363534 T1 : 0x7271706f T2 : 0x33323130
17:47:39.956 -> S0/FP : 0x3fc95912 S1 : 0x00000065 A0 : 0x3fc957e4 A1 : 0x3fc8c78d
17:47:39.956 -> A2 : 0x00000001 A3 : 0x00000029 A4 : 0x00000001 A5 : 0x3fc8e000
17:47:39.956 -> A6 : 0x7a797877 A7 : 0x76757473 S2 : 0x3fc957d8 S3 : 0x00000001
17:47:39.989 -> S4 : 0x3fc957d8 S5 : 0x4200e4d0 S6 : 0x00000000 S7 : 0x00000000
17:47:39.989 -> S8 : 0x00000000 S9 : 0x00000000 S10 : 0x00000000 S11 : 0x00000000
17:47:39.989 -> T3 : 0x6e6d6c6b T4 : 0x6a696867 T5 : 0x66656463 T6 : 0x62613938
17:47:39.989 -> MSTATUS : 0x00001801 MTVEC : 0x40380001 MCAUSE : 0x00000007 MTVAL : 0x00000000
17:47:39.989 -> MHARTID : 0x00000000
17:47:39.989 ->
17:47:39.989 -> Stack memory:
17:47:39.989 -> 3fc95780: 0x3fc8edd0 0x00000000 0x3c042ee0 0x40389dda 0x0000000c 0x3fc8f4c8 0x00000804 0x3fc8c78c
17:47:40.022 -> 3fc957a0: 0x3fc95ba4 0x00000000 0x00000020 0x00353534 0x0000000e 0x3fc8c874 0x3c042ee0 0x3fc8c858
17:47:40.022 -> 3fc957c0: 0x3c042f54 0x3fc8c884 0x3fc957ac 0x3fc8c888 0x3c042f08 0x3fc8c78c 0x00000000 0x00000000
17:47:40.022 -> 3fc957e0: 0x00000000 0x65737361 0x66207472 0x656c6961 0x74203a64 0x70697063 0x6e65735f 0x736d5f64
17:47:40.022 -> 3fc95800: 0x61775f67 0x735f7469 0x49206d65 0x632f4644 0x6f706d6f 0x746e656e 0x776c2f73 0x6c2f7069
17:47:40.022 -> 3fc95820: 0x2f706977 0x2f637273 0x2f697061 0x69706374 0x3a632e70 0x20353534 0x766e4928 0x64696c61
17:47:40.088 -> 3fc95840: 0x6f626d20 0x3f002978 0xc0380000 0x00000058 0x3fc8edd0 0x00000000 0x3fc8edd0 0x403897f8
17:47:40.088 -> 3fc95860: 0x3fc8edd0 0x00000000 0x3fc8edd0 0xbaad5678 0x00000000 0x00000000 0x00000054 0x40389992
17:47:40.088 -> 3fc95880: 0x00000054 0x3fc8f4c8 0x00001800 0x4038202a 0x00000000 0x00000000 0x00000000 0x00000000
17:47:40.088 -> 3fc958a0: 0x00000000 0x00000000 0x00000000 0xe5944b8b 0x00001800 0x00000000 0x00000000 0x00000000
17:47:40.088 -> 3fc958c0: 0x00000000 0x4201ad8e 0x3fc95918 0x4200e4d0 0x00000000 0x4201ad8e 0x3fc95918 0x00000000
17:47:40.122 -> 3fc958e0: 0x00000000 0x4201ad8e 0x3fc8ff24 0x42019f6e 0x4200dd4e 0x00000018 0x3fc95918 0x42019fac
17:47:40.122 -> 3fc95900: 0x00000000 0x00000000 0x3fc96268 0x42019fe4 0x00000000 0x00000000 0x3fc96268 0x00000000
17:47:40.122 -> 3fc95920: 0x00000000 0x3fc8e000 0x00000006 0x42000380 0x00000001 0x3c0421e0 0x3fc8e000 0x3fc8ff24
17:47:40.122 -> 3fc95940: 0x00000000 0x3fc8e000 0x3fc8e000 0x4200e3a6 0x00000000 0x3fc8e000 0x3fc8e000 0x4200005c
17:47:40.122 -> 3fc95960: 0x50000a00 0x32333835 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc8d000 0xe5944b8b
17:47:40.155 -> 3fc95980: 0x00000000 0x3fc8e000 0x42000000 0x42000c80 0x00000000 0x00000000 0x00000000 0x403872dc
17:47:40.155 -> 3fc959a0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5
17:47:40.155 -> 3fc959c0: 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xbaad5678 0x00000160 0xabba1234 0x00000154 0x3fc95920
17:47:40.155 -> 3fc959e0: 0xd15db147 0x3fc8dcec 0x3fc8dcec 0x3fc959dc 0x3fc8dce4 0x00000018 0x0bf777f3 0x99c5b4dc
17:47:40.155 -> 3fc95a00: 0x3fc959dc 0x00000000 0x00000001 0x3fc939cc 0x706f6f6c 0x6b736154 0xf74e3400 0x005660ca
17:47:40.188 -> 3fc95a20: 0x00000000 0x3fc959c0 0x00000001 0x00000000 0x00000000 0x00000000 0x00000000 0x3fc8f7d4
17:47:40.188 -> 3fc95a40: 0x3fc8f83c 0x3fc8f8a4 0x00000000 0x00000000 0x00000001 0x00000000 0x00000000 0x00000000
17:47:40.188 -> 3fc95a60: 0x42025d28 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
17:47:40.188 -> 3fc95a80: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
17:47:40.188 -> 3fc95aa0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
17:47:40.254 -> 3fc95ac0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
17:47:40.254 -> 3fc95ae0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
17:47:40.254 -> 3fc95b00: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
17:47:40.254 -> 3fc95b20: 0x00000000 0x00000000 0x00000000 0xac000000 0xbaad5678 0x00000060 0xabba1234 0x00000054
17:47:40.254 -> 3fc95b40: 0x00000000 0x3fc95b40 0x00000000 0x00000000 0x00000000 0x3fc95b58 0xffffffff 0x3fc95b58
17:47:40.287 -> 3fc95b60: 0x3fc95b58 0x00000000 0x3fc95b6c 0xffffffff 0x3fc95b6c 0x3fc95b6c 0x00000001 0x00000001

It seems that wifi need to be started before configuring anything network related.
Sad that it crash instead of saying "ERROR: network is not started"

Thanks for your hints and help. It works now