• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

[SOLVED]assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1851 (Required to lock TCPIP core functionality!)

Q&A Forum › Category: ESP32 › [SOLVED]assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1851 (Required to lock TCPIP core functionality!)
1 Vote Up Vote Down
Sara Santos Staff asked 1 year ago

ISSUE:

In most of our web server and MQTT projects, we use the following libraries (that are currently deprecated):

  • ESPASyncWebServer: https://github.com/me-no-dev/ESPAsyncWebServer
  • AsyncTCP: https://github.com/me-no-dev/asynctcp

Using these libraries will result in the following error and constant rebooting of the ESP32:

assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1851 (Required to lock TCPIP core functionality!)

 

SOLUTION:

To fix this issue, you must use the newest fork of those libraries, available on the following links:

  • ESPAsyncWebServer: https://github.com/ESP32Async/ESPAsyncWebServer (at least version 3.6.2)
  • AsyncTCP: https://github.com/ESP32Async/AsyncTCP (at least version 3.3.2)

 

Follow these instructions to solve the issue:

  • Go to the Arduino Libraries Manager: Sketch > Include Library > Manage Libraries
  • UNINSTALL any previous versions of the ESPAsyncWebServer and AsyncTCP libraries
  • Now, you can install the latest version of the new fork.  Follow the next instructions:

To guarantee that you’re using the latest version of the ESPAsyncWebServer and AsyncTCP libraries, please install them via ZIP folder (don’t use the Library Manager that will currently install an older version with issues).

Click the following links to download the library files.

  • Click here to download the ESPAsyncWebServer
  • Click here to download the Async TCP library.

In your Arduino IDE, go to Sketch > Include Library > Add .zip Library and select the libraries you’ve just downloaded.

 

Compile your code again. This will work with the latest version of the ESP32 core.

 

 

 

13 Answers
0 Vote Up Vote Down
Brian answered 9 months ago

I have a MQTT project in VSCode / Platformio that at one time ran great on my esp32-s3 and RPI-5.  I attempted to upgrade the code but once downloaded I get the following error
”  assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1851 (Required to lock TCPIP core functionality!)”
Here is a list of included files:

#include <Arduino.h>
#include <OneWire.h>
#include “DallasTemperature.h”
#include <WiFi.h>
#include <AsyncMqttClient.h>
#include <string>

extern “C”
{
#include “freertos/FreeRTOS.h”  //
#include “freertos/timers.h”
}

 
and libraries:

lib_deps =
    marvinroger/AsyncMqttClient@^0.9.0
    paulstoffregen/OneWire@^2.3.8
    milesburton/DallasTemperature@^4.0.5
 

I’m not using the ESPAsyncWebServer or AsyncTCP libraries.  Please help me figure out how to clear this error.
 

 
 

0 Vote Up Vote Down
Sara Santos Staff answered 9 months ago

Hi.
When you say you atempted to upgrade the code, what do you mean exactly?
Can you share your complete plaformio.ini file?
 
Regards,
Sara

0 Vote Up Vote Down
Brian answered 9 months ago

There were some features of my original working program that I wanted to improve.  When I made the changes I started to receive the error and reboot issue.  Even when I reflashed the esp with the once working version the problem remains.  As the program was written several years back, there have been changes to the api version and I since changed to pioarduino.  Here is a copy of the full platformio.ini file minus the comments:

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
lib_deps =
    marvinroger/AsyncMqttClient@^0.9.0
    paulstoffregen/OneWire@^2.3.8
    milesburton/DallasTemperature@^4.0.5

0 Vote Up Vote Down
Brian answered 9 months ago

Thanks for looking at this.  I asked copilot to look at the code and his suggestions fixed the issue.  Here is the output summary:
 
Patch applied — changes summary:
Added lwIP header include: #include “lwip/tcpip.h”
Added function connectOnTcpipThread(void*) that calls mqttClient.connect().
Replaced direct mqttClient.connect() call in the main loop with tcpip_callback(connectOnTcpipThread, NULL).
Why this should fix the assert
tcpip_callback schedules a function to run on the lwIP TCPIP thread while holding the required TCPIP core lock. Any allocations or TCP operations performed there won’t trigger the tcp_alloc assert.
This is safer than calling connect() from event/timer contexts or even the main loop if the library expects to run on the TCPIP thread.
 

0 Vote Up Vote Down
Sara Santos Staff answered 9 months ago

Hi.
Thanks for sharing that.
We would have suggested adding the following line to your platformio.ini file:

platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip

 
Instead of:

platform = espressif32

 
But, if it is working as expected now, it’s better to proceed at it is.
 
Regards,
Sara
 

0 Vote Up Vote Down
Brian answered 9 months ago

Thanks Much

0 Vote Up Vote Down
Gerald answered 5 months ago
further Infos on following error message:
assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1854 (Required to lock TCPIP core functionality!)

Why works PubSubClient, but not AsyncMqttClient together with an older version of AsyncTCP for Arduino-IDE 2.x ?
Library
Eigener Task?
FreeRTOS‑Timer?
LWIP‑safe?
CYD‑Board stabil?
AsyncMqttClient
Ja
Ja
Nein
❌ Crash
PubSubClient
Nein
Nein
Ja
✔️ stabil

Pls check and remove the entire directory of older versions of AsyncTCP and use the forked version, provided by Sara. Check the compiler-output to ensure which version is taken ..

0 Vote Up Vote Down
Sara Santos Staff answered 5 months ago

The AsyncMQTT library that we recommend works.
It’s a forked version that we created: https://github.com/RuiSantosdotme/async-mqtt-client/
You must install it via .ZIP file.
 
Regards,
Sara

0 Vote Up Vote Down
Gerald answered 5 months ago

Hi Sara,
I have exactly this lib from your link installed (async-mqtt-client-develop.zip), included by the Arduino-IDE 2.3.7.
Additional I have the Async TCP from ESP32Async, V 3.4.10 by the lib-manager installed.
When running the examples 5_6_1_MQTT_Publish_Button_Counter.ino or 5_6_2_MQTT_Publish_Button_On_Off.ino, then there are cyclic SW-Resets with the error-message:

WiFi connected
IP address: 
192.168.178.76
Connecting to MQTT...
assert failed: tcp_alloc /IDF/components/lwip/lwip/src/core/tcp.c:1854 (Required to lock TCPIP core functionality!)
After some research I found the PubSubClient-Lib, thread-safe running without timers and tasks. 
Afterwards also both arduino-programs are stable running together with node-red.

update from 14.02.26:
An older version of AsyncTCP was taken by the compliler, although that is not installed, but physically located
on disc (inside  ..\Arduino15\lib..).
0 Vote Up Vote Down
Gerald answered 5 months ago

update:
Hi Sara,
I have now applied the patch, described by Brian. Now it works fine with Async_TCP from ESP32Async, V 3.4.10 and async-mqtt-client-develop.zip. In this context, I found, that the arduino-IDE has used an older version of AsyncTCP, although I did install the correct one additionally. This was apparently the root cause for the cyclic SW-Resets ..

0 Vote Up Vote Down
Sara Santos Staff answered 5 months ago

Hi.
Great.
I’m glad it is working now.
But, did you try with our version of the library? Our fork?
Because for me, it works as expected without further modifications.
 
Regards,
Sara

0 Vote Up Vote Down
Gerald answered 5 months ago

Hi Sara,
thank-you for your fast response.
You are right, the mqtt-client on the CYD is now working as expected with your forked lib “AsyncTCP-main.zip” (Arduino-IDE shows V 3.4.10 from ESP32Async).
I suppose the problem is (was), that an older version of AsyncTCP (although it wasn’t installed inside the Arduino-IDE 2.x), rather possibly installed on an previous Arduino-Version 1.x in the past was taken:
c:\Users\gerald\AppData\Local\Arduino15\libraries\AsyncTCP. In the context of troubleshooting I found, that the Arduino-IDE (2.3.7) has taken this version, and reported that the your forked version was only detected, but not applied. So I have this lib physically removed under ..\Arduino15\ ..  and the mqtt-client works correctly !!!
Pls excuse my confusion, I’m very sorry.

PS: The patched version from Brian combined with the older version of AsyncTCP, that is leading not longer to a SW-Reset, but the mqtt-client does not connect to the broker !!

Regards,
Gerald

0 Vote Up Vote Down
Sara Santos Staff answered 5 months ago

No problem.
I’m glad everything is working as expected.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Smart Home with Raspberry Pi, ESP32, and ESP8266 Version 1.7 November 28, 2025
  • [eBook Updated] Smart Home with Raspberry Pi, ESP32, and ESP8266 V1.6 September 9, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2026 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.