Skip to content

UDP Crash with versions above 2.5.2 #6831

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

Closed
SvenSiwek opened this issue Nov 24, 2019 · 28 comments · Fixed by #6895
Closed

UDP Crash with versions above 2.5.2 #6831

SvenSiwek opened this issue Nov 24, 2019 · 28 comments · Fixed by #6895

Comments

@SvenSiwek
Copy link

SvenSiwek commented Nov 24, 2019

Basic Infos

  • [X ] This issue complies with the issue POLICY doc.
  • [ X] I have read the documentation at readthedocs and the issue is not addressed there.
  • [ X] I have tested that the issue is present in current master branch (aka latest git).
  • [ X] I have searched the issue tracker for a similar issue.
  • [ X] If there is a stack dump, I have decoded it.
  • [X ] I have filled out all fields below.

Platform

  • Hardware: [ESP8266]
  • Core Version: [2.6.0 & 2.6.1]
  • Development Env: [Arduino IDE]
  • Operating System: [Windows]

Settings in IDE

  • Module: [LOLIN (WEMOS) D1 R2 & mini]
  • Flash Mode: [qio|dio|other]
  • Flash Size: [4MB]
  • lwip Variant: [v1.4|v2 Lower Memory|Higher Bandwidth]
  • Reset Method: [ck|nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz|]
  • Upload Using: [OTA|SERIAL]
  • Upload Speed: [other]

Problem Description

I am pretty new to this all. So please be polite with me.
I do have a working sketch with version 2.5.2.
I updated to 2.6.1
The WEMOS does reboot after a certain time (10 to 15 seconds) with heavy ingoing udp traffic.

I downgraded to 2.6.0
The WEMOS does reboot after a certain time (10 to 15 seconds) with heavy ingoing udp traffic.

I downgraded to 2.5.2
The WEMOS does work as expected.

Since I am pretty new to this all (NodeEMU etc),
is there a "how to" to provide you with additional infos - if needed?

I am willing to help...

Sven

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

// Wi-Fi network to connect to (if not in AP mode)
 char* ssid = "XXXXXX";
 char* password = "XXXXXXXXXXXXXXXXXXXX";
 
#define BUFFER_LEN 1024
unsigned int localPort = 7777;

// buffers for receiving and sending data
char packetBuffer[1024]; //buffer to hold incoming packet,


// An EthernetUDP instance to let us send and receive packets over UDP
WiFiUDP port;

void setup() {
  WiFi.setSleepMode(WIFI_NONE_SLEEP);
  Serial.begin(115200);
  delay(100);
  Serial.setDebugOutput(true);

  Serial.println();
  Serial.print( F("Heap: ") ); Serial.println(system_get_free_heap_size());
  Serial.print( F("Boot Vers: ") ); Serial.println(system_get_boot_version());
  Serial.print( F("CPU: ") ); Serial.println(system_get_cpu_freq());
  Serial.print( F("SDK: ") ); Serial.println(system_get_sdk_version());
  Serial.print( F("Chip ID: ") ); Serial.println(system_get_chip_id());
  Serial.print( F("Flash ID: ") ); Serial.println(spi_flash_get_id());
  Serial.print( F("Flash Size: ") ); Serial.println(ESP.getFlashChipRealSize());
  Serial.print( F("Vcc: ") ); Serial.println(ESP.getVcc());
  Serial.println();
  WiFi.mode(WIFI_STA);
  Serial.printf("Connecting to %s\n", ssid);
  if (String(WiFi.SSID()) != String(ssid)) {
    WiFi.begin(ssid, password);
  }
  delay(1000);
  port.begin(localPort);
  Serial.println("UDP started"); 
 
 
}
void loop() {
  // if there's data available, read a packet
  int packetSize = port.parsePacket();
  if (packetSize) {
    // read the packet into packetBufffer
    int len = port.read(packetBuffer, BUFFER_LEN);
    Serial.print("Packet.\n");
  }
  delay(100);
  Serial.print("Round.\n");
}

On Linux do

$ cat /dev/random | netcat -u  172.16.178.41 7777

Result:

Round.
Packet.
Fatal exception 29(StoreProhibitedCause):
epc1=0x4000df64, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

Exception (29):
epc1=0x4000df64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: sys
sp: 3fffec10 end: 3fffffb0 offset: 01a0
3fffedb0:  4021f643 0000b5bc 00000005 4021f5d8  
3fffedc0:  00000002 4021f57f 00000002 4021e6d8  
3fffedd0:  4021e701 3fffee80 3ffed9c8 00000016  
3fffede0:  4021c174 3fffee80 3ffed874 3ffed200  
3fffedf0:  3ffe9cc0 3fffee80 3fffee80 00000000  
3fffee00:  534d4853 03c9ef00 4010274a 00000100  
3fffee10:  3ffe962c 7fffffff 00000000 00000001  
3fffee20:  402184d5 00000080 00000022 00000000  
3fffee30:  ffffffcf 3ffed388 3ffe9cd0 3ffed9c8  
3fffee40:  3ffec830 0000002f 00000000 4021ce6b  
3fffee50:  00000000 3ffef31c ffffffcf 00000000  
3fffee60:  00000000 3ffed9c8 00000010 0000000f  
3fffee70:  40000f58 00000000 45fad8c3 00000000  
3fffee80:  00000000 00310101 00640100 00000043  
3fffee90:  3ffe9ce4 00000038 3ffe9cf7 3ffe9cd8  
3fffeea0:  00000000 3ffe9ce4 3ffe9cea 3ffe9d00  
3fffeeb0:  00000000 00000000 3ffe9d06 00000000  
3fffeec0:  00000000 00000000 00000000 00000000  
3fffeed0:  00000000 00000000 0000002f 00000000  
3fffeee0:  3ffef6e4 4021c8de 3ffec830 3ffef31c  
3fffeef0:  00000000 3ffed9c8 3ffec830 3ffe9cc0  
3fffef00:  3ffe9cc0 00000060 00000000 0000002f  
3fffef10:  00000000 3ffe9cca 40226023 3ffec830  
3fffef20:  3ffe9cb4 3fffdcc0 3ffe8e68 3ffe8e68  
3fffef30:  00000080 3ffec830 00000000 3fffdcb0  
3fffef40:  402258e3 3fffdab0 00000000 4022c813  
3fffef50:  3ffe8e68 40000f49 3fffdab0 40000f49  
3fffef60:  40000e19 40001878 00000002 00000000  
3fffef70:  3fffff10 401048a5 40001878 00000002  
3fffef80:  401048ab 46060c02 42620005 01678002  
3fffef90:  4010000d 21616063 60016680 063d3168  
3fffefa0:  402247c4 3fffef3c 4022477d 3fffff68  
3fffefb0:  3fffffc0 00000000 00000000 feefeffe  
3fffefc0:  feefeffe feefeffe feefeffe feefeffe  
3fffefd0:  feefeffe feefeffe feefeffe feefeffe  
3fffefe0:  feefeffe feefeffe feefeffe feefeffe  
3fffeff0:  feefeffe feefeffe feefeffe feefeffe  
3ffff000:  feefeffe feefeffe feefeffe feefeffe  
[...]
3ffffc90:  feefeffe feefeffe feefeffe feefeffe  
3ffffca0:  feefeffe feefeffe feefeffe feefeffe  
3ffffcb0:  feefeffe feefeffe feefeffe 00000000  
3ffffcc0:  3ffffe20 00000000 3ffffe20 4020a51e  
3ffffcd0:  feefeffe 3ffffdc3 feefeffe feefeffe  
3ffffce0:  feefeffe feefeffe feefeffe 00000004  
3ffffcf0:  3ffffe20 00000004 3ffffe20 4020a51e  
3ffffd00:  feefeffe 3ffe86a8 3ffffd30 feefeffe  
3ffffd10:  feefeffe feefeffe feefeffe 4020a454  
3ffffd20:  3ffffe20 3ffe86a8 3ffffd80 402068a8  
3ffffd30:  00000004 feefeffe feefeffe 00000001  
3ffffd40:  00000000 00000001 3ffffe20 4020a51e  
3ffffd50:  feefeffe 3ffe8678 feefeffe feefeffe  
3ffffd60:  feefeffe feefeffe feefeffe 3ffe8678  
3ffffd70:  00000000 3ffe8679 3ffffe20 4020a708  
3ffffd80:  00000000 00000004 00000000 00000000  
3ffffd90:  00000004 00000013 fe302073 feefeffe  
3ffffda0:  feefeffe feefeffe feefeffe feefeffe  
3ffffdb0:  feefeffe feefeffe feefeffe feefeffe  
3ffffdc0:  0000000a 40104a88 0000000a 00000000  
3ffffdd0:  40001da0 0000000a 00000000 feefeffe  
3ffffde0:  3fffff50 3fffff20 0000000c 3ffe8304  
3ffffdf0:  00000004 00000001 00000000 feefeffe  
3ffffe00:  3ffecf20 4010261b feefeffe 3ffeeae8  
3ffffe10:  3ffee9bc 3ffe8304 00000040 40207ef1  
3ffffe20:  3ffffee3 2c9f0300 0000002c ffff0208  
3ffffe30:  3ffffed0 0000003f 000000cb 401006a4  
3ffffe40:  40228f77 3fffff20 3fffff20 3ffeeae8  
3ffffe50:  3fffff20 3ffef83c 00000020 4010092f  
3ffffe60:  3ffeeae8 00000000 00000004 fffffffe  
3ffffe70:  ffffffff 00000000 00000004 401002e8  
3ffffe80:  00000004 00000000 000a534d 40203e51  
3ffffe90:  3ffed3bf 00000004 3fffff7c 40202cd4  
3ffffea0:  3ffe84c8 3fffff7c 3fffff30 40202d0a  
3ffffeb0:  000005e8 3ffee980 3fffff7c 40201c48  
3ffffec0:  534d4853 00000000 00000000 00000001  
3ffffed0:  00001e61 3ffee568 00000020 40100964  
3ffffee0:  32313732 63697361 6c656773 37363931  
3ffffef0:  3ffe86b5 00000000 616e000a 40203e51  
3fffff00:  3ffe86b5 00000000 61500064 40203e51  
3fffff10:  3ffe8685 3ffee568 00000020 00000001  
3fffff20:  00001170 0000022e 0000022e 401006a4  
3fffff30:  3ffe868e 00000000 52000a2e 40203e51  
3fffff40:  3ffe868e 3fff02c4 00000020 4010092f  
3fffff50:  401050c5 012f3f0a 3ffeeb48 00000000  
3fffff60:  3ffee0b0 3ffeeb48 00000064 3ffeeb48  
3fffff70:  3fffdad0 3ffeeae8 40202fa4 3fffefa0  
3fffff80:  3ffeeb48 3fffdad0 3ffeeae8 4020359b  
3fffff90:  3fffdad0 3ffee9bc 3ffee568 40201204  
3fffffa0:  3fffdad0 00000000 3ffeeaa8 402030d4  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v482516e3
~ld
⸮bl`�r⸮n�lph⸮
Heap: 51016
Boot Vers: 6
CPU: 80
SDK: 2.2.2-dev(5ab15d1)
Chip ID: 6637503
Flash ID: 1458208
Flash Size: 4194304
Vcc: 65535

Connecting to SHMS
UDP started
scandone
state: 0 -> 2 (b0)
Round.
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 6
cnt 
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.

connected with SHMS, channel 1
dhcp client start...
ip:172.16.178.41,mask:255.255.255.0,gw:172.16.178.1
Round.
Packet.
Round.
Packet.
Round.
Packet.
Round.
Packet.
Round.
Packet.
Round.
Packet.
Fatal exception 29(StoreProhibitedCause):
Fatal exception 29(StoreProhibitedCause):
Fatal exception 29(StoreProhibitedCause):
Fatal exception 29(StoreProhibitedCause):
Fatal exception 29(StoreProhibitedCause):
Fatal exception 29(StoreProhibitedCause):
Fatal exception 29(StoreProhib
 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v482516e3
~ld
⸮bl`�r⸮n�lph⸮
Heap: 51016
Boot Vers: 6
CPU: 80
SDK: 2.2.2-dev(5ab15d1)
Chip ID: 6637503
Flash ID: 1458208
Flash Size: 4194304
Vcc: 65535

Connecting to SHMS
UDP started
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 6
cnt 
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.
Round.

connected with SHMS, channel 1
dhcp client start...
ip:172.16.178.41,mask:255.255.255.0,gw:172.16.178.1
Round.
Round.
@TD-er
Copy link
Contributor

TD-er commented Nov 24, 2019

Do you "server" the UDP related code with regular intervals?
Just like "serving" the webserver, you must also make regular calls to see what packets have to be processed for UDP.

@devyte
Copy link
Collaborator

devyte commented Nov 24, 2019

@SvenSiwek the issue template you filled out requires an MCVE. Without that there isn't much we can do.
Please edit your OP and add a MCVE sketch with which the issue can be reproduced. If there is additional info involved, such as needing a linux script or similar to reproduce, please add that as well.

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Nov 24, 2019
@SvenSiwek
Copy link
Author

Okay I found out what MCVE means. I ll provide one.

It would be fine if you explain what OP means, which I have to edit.

My English is not that good, and as I wrote I am new to this.
Thx
Sven

@devyte
Copy link
Collaborator

devyte commented Nov 24, 2019

Original Post

@TD-er
Copy link
Contributor

TD-er commented Nov 25, 2019

On Linux do

cat /dev/random | netcat -u 172.16.178.41 7777

Hmm that sounds like "lots of traffic" and "large packets".
Both are a very good receipt for crashes on these units.
Have you also tried limiting the speed by setting an interval (-i) and maybe also use shorter messages.
I don't know what netcat will consider a chunk of data, when processing /dev/random.

@devyte
Copy link
Collaborator

devyte commented Nov 25, 2019

You are processing packets once per loop. You also have delay(100) in the loop. That effectively limits you to 10 packets per second. If you send faster than that, the esp will accumulate them, run out of mem, and crash.
Closing due to user error.

@devyte devyte closed this as completed Nov 25, 2019
@devyte
Copy link
Collaborator

devyte commented Nov 25, 2019

Also, you're reading at most 1024 bytes into the buffer. If the packet is bigger, there are remaining bytes unread.

@SvenSiwek
Copy link
Author

Why do you close this?

This ist not an user error. You're really doing it very easy.

If I send too many packets too fast, that's my problem. The nodemcu must therefore not crash. If she loses packages that's okay.

I checked my MCVE against 2.5.2 which works as expected without any crash.

So I will stick to that version.

Thank you for taking my time.
I will think for the future again to report errors, if I am helped in this way.
Translated with Google.

Sven

@d-a-v d-a-v self-assigned this Nov 25, 2019
@devyte
Copy link
Collaborator

devyte commented Nov 25, 2019

I closed because I still don't see a core issue. That does not mean end of discussion.
Also, if what you need is general help, this is not the place for it, because this is an issue tracker, meant for tracking issues in the core, and not a general support forum.
Finally, your reports help yourself before anyone else, because you are the user faced with the issue. In this case, as the primary interested party, it is up to you to continue investigating and providing info, until you either show a core issue, in which case I'll reopen, or you find a mistake in your code, in which case you'll probably immediately realize how to fix it.

As for 2.5.1, it would intermittently lose incoming packets independently of receiving speed, and that was addressed. If you don't want to process all incoming, it is your responsibility to receive and discard unwanted packets, because there is no way to differentiate between your use case of unwanted packets and somebody else who wants to maximize reception.
And btw, it is true that udp packets can get dropped in traffic, but it is not ok to receive packets and lose them in our software before passing them to the user app.

@SvenSiwek
Copy link
Author

Hi,
I opened this issue, because something that works with 2.5.2 does not work with 2.6.1 and up.

If you arent interested in finding the cause of that, than it is that way,

For me its pretty easy. I generate an udp stream of packets on the server side.
It is not importand for me that every single udp arrives in the sketch.

But this packet stream should not crash the device - under no circumstances.
This is what happens with version 2.6.1 and up.

So, too much udp packets in a to short timerange crashes the device. That is core.

Sven

@TD-er
Copy link
Contributor

TD-er commented Nov 25, 2019

@SvenSiwek Please read his reply again.
It was an intentional change (aka. bug fix) to change behavior and not drop packets.
I do agree the result is somewhat unfortunate, to cause a crash.

Maybe you can change the function in your code to read the entire packet (read until packet length is processed) and also not waiting for 100 msec every loop.
In a few 100 msec the memory of the ESP is full when receiving at max. speed, especially if you only read 1024 bytes.
Also I am not entirely sure your code does continue to read on the same packet if you go through the next loop. So that may leave the rest of the packet in RAM, causing the RAM to fill up and all kinds of things will then fail as lots of memory allocations will fail.

@SvenSiwek
Copy link
Author

Hi,

the goal, at last for me was, to provide a MCVE, which I did.

If a bug fix results in somewhat like a possible DoS it is not a good one.
Maybe you can install a switch to get the old behavior back.

To the root of that :
My daughter wanted to have a nice light show with LEDs, which she can control via mobile phone.
As I myself am a programmer (COBOL, Java, PHP), I thought, can not be that hard and I came across the ESP and fastled.
That works great https://github.com/jasoncoon/esp8266-fastled-webserver .
That was not enough for us. It should also give great effects to match music. Then I found https://github.com/scottlawsonbc/audio-reactive-led-strip .

I have combined both in a sketch and it works fine - just up to version 2.5.2.

Now there was the update to 2.6.1 and higher.
It does not work with these versions.
I thought, okay then I'll call it. Something does not seem to work as it should.

The Visualization-Server sends UDP light instructions to the ESP. Always 4 bytes. The first byte Addresses the number of the LED. The other three bytes are RGB color values.

The source code has remained pretty much the same.

Translated with Google
Sven

@SvenSiwek
Copy link
Author

SvenSiwek commented Nov 28, 2019

@SvenSiwek Please read his reply again.
It was an intentional change (aka. bug fix) to change behavior and not drop packets.
I do agree the result is somewhat unfortunate, to cause a crash.

Maybe you can change the function in your code to read the entire packet (read until packet length is processed) and also not waiting for 100 msec every loop.
In a few 100 msec the memory of the ESP is full when receiving at max. speed, especially if you only read 1024 bytes.
Also I am not entirely sure your code does continue to read on the same packet if you go through the next loop. So that may leave the rest of the packet in RAM, causing the RAM to fill up and all kinds of things will then fail as lots of memory allocations will fail.

I debugged this more: It is not a memory problem visible to the sketch

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
// Wi-Fi network to connect to (if not in AP mode)
 char* ssid = "XXXXXXXXX";
 char* password = "XX";
WiFiUDP port;
// Maximum number of packets to hold in the buffer.
#define BUFFER_LEN 2048

char packetBuffer[ BUFFER_LEN + 1];

IPAddress mc_groupIP = IPAddress(233, 233, 233, 233);
unsigned int mc_localUdpPort = 4711;  // local port to listen on

int len;

void setup() {
  WiFi.setSleepMode(WIFI_NONE_SLEEP);

  Serial.begin(115200);
  delay(100);
  Serial.setDebugOutput(true);
  WiFi.mode(WIFI_STA);
  Serial.printf("Connecting to %s\n", ssid);
  if (String(WiFi.SSID()) != String(ssid)) {
    WiFi.begin(ssid, password);
  }
   while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(500);
  }

  Serial.println("Listening UDP");
  port.beginMulticast(WiFi.localIP(), mc_groupIP, mc_localUdpPort);

  

}

void loop() {
  // put your main code here, to run repeatedly:
  int packetSize = port.parsePacket();
  // If packets have been received, interpret the command
  if (packetSize) {
    Serial.print("P");
    Serial.println(packetSize);
    // Read data over socket
    len = port.read(packetBuffer, BUFFER_LEN);
    Serial.print("L");
    Serial.println(len);
  }  
}

The only thing this sketch does is println...

And here is the result:

ip:172.16.178.32,mask:255.255.255.0,gw:172.16.178.1
Connecting to SHMS
HTTP web server started
Listening UDP
pm open,type:0 0
P300
L300
P300
L300
P472
L472
P472
L472
P440
L440
P448
L448
P456
L456
P440
L440
P300
L300
P300
L300
P440
L440
[...]
P160
L160
P152
L152
P160
L160
P168
L168
P152
L152
Fatal exception 0(IllegalInstructionCause):
epc1=0x40241abc, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

Exception (0):
epc1=0x40241abc epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: sys
sp: 3fffebf0 end: 3fffffb0 offset: 01a0
3fffed90:  400005e1 40102a5f 000000ff 00000000  
3fffeda0:  40224f3c 00000030 00000010 0000c60e  
3fffedb0:  40224e05 00001267 e9e9e9e9 42b210ac  
3fffedc0:  3fff3074 3fff0d94 00000000 3fff3074  
3fffedd0:  00000000 00000006 00000000 00000000  
3fffede0:  00000000 3fff3486 3fff3454 00000000  
3fffedf0:  00000000 00000098 00000098 00000001  

@d-a-v
Copy link
Collaborator

d-a-v commented Nov 28, 2019

Your stack trace is personal, only you can decode it.

Thanks, we need to reproduce the issue to fix it.

Do you have any idea of the packet frequency ?

@d-a-v d-a-v added component: network type: troubleshooting and removed waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. labels Nov 28, 2019
@d-a-v d-a-v reopened this Nov 28, 2019
@SvenSiwek
Copy link
Author

To explain I use that python mentioned above.
https://github.com/scottlawsonbc/audio-reactive-led-strip

I do have 150Led * 4 Byte * 60Hz. ~ 36.000Bytes/s max.

I will test with lower Hz.

0x40204699: loop() at D:\Users\svens\Documents\Arduino\udp_kaputt/udp_kaputt.ino line 69
0x402046a9: loop() at D:\Users\svens\Documents\Arduino\udp_kaputt/udp_kaputt.ino line 73
0x40209020: loop_wrapper() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 180

Line 69 int packetSize = port.parsePacket();
Line 73 Serial.println(packetSize);

And a second one

Decoding stack results
0x40216ba0: pbuf_alloc_LWIP2 at core/pbuf.c line 186
0x40216ba0: pbuf_alloc_LWIP2 at core/pbuf.c line 186
0x4021cc0c: sntp_init at apps/sntp/sntp.c line 670
0x40212af2: netif_sta_status_callback at glue-lwip/lwip-git.c line 331
0x40216ba0: pbuf_alloc_LWIP2 at core/pbuf.c line 186
0x40216b7c: pbuf_alloc_LWIP2 at core/pbuf.c line 284
0x4021cd60: mem_free at core/mem.c line 237
0x40214a89: sys_check_timeouts at core/timeouts.c line 390
0x40214a84: sys_check_timeouts at core/timeouts.c line 389
0x4021c9a8: sntp_request at apps/sntp/sntp.c line 604
0x40100a4c: malloc(size_t) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 511
0x4021cd40: mem_malloc at core/mem.c line 210
0x40216b7c: pbuf_alloc_LWIP2 at core/pbuf.c line 284
0x4021c9a8: sntp_request at apps/sntp/sntp.c line 604
0x4021c938: sntp_send_request at apps/sntp/sntp.c line 546
0x4021c9a8: sntp_request at apps/sntp/sntp.c line 604
0x4021c9f8: sntp_request at apps/sntp/sntp.c line 634
0x40213089: memp_free at core/memp.c line 447
0x40214a8c: sys_check_timeouts at core/timeouts.c line 390
0x40210ce2: __ssputs_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 233
0x40210ce2: __ssputs_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 233
0x40210c18: __ssputs_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 180
0x4020ceb8: _printf_i at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf_i.c line 244
0x40210ce2: __ssputs_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 233
0x40210ecc: _svfprintf_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 531
0x4020e631: _vsnprintf_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/vsnprintf.c line 73
0x4010078c: umm_free_core(void*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 316
0x40100a17: free(void*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 362
0x40100384: vPortFree(void*, char const*, int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\heap.cpp line 308
0x40209f71: uart_write(uart_t*, char const*, size_t) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\uart.cpp line 509
0x40207f2c: String::copy(char const*, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\WString.cpp line 214
0x40207f62: String::String(char const*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\WString.cpp line 36
0x4020524d: ESP8266WiFiSTAClass::SSID() const at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 659
0x40205268: ESP8266WiFiSTAClass::SSID() const at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 662
0x4020ca66: _printf_common at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf_i.c line 102
0x4020c81c: _printf_float at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf_float.c line 327
0x402018fc: esp8266webserver::ESP8266WebServerTemplate ::_parseForm(WiFiClient&, String const&, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WebServer\src/Parsing-impl.h line 396
0x40204f30: ESP8266WiFiSTAClass::config(IPAddress, IPAddress, IPAddress, IPAddress, IPAddress) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 332
0x40204f30: ESP8266WiFiSTAClass::config(IPAddress, IPAddress, IPAddress, IPAddress, IPAddress) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 332
0x40204f30: ESP8266WiFiSTAClass::config(IPAddress, IPAddress, IPAddress, IPAddress, IPAddress) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 332
0x40208f08: __esp_yield() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 100
0x40209516: __delay(unsigned long) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_wiring.cpp line 54
0x40203751: setup() at D:\Users\svens\Documents\Arduino\udp_kaputt/udp_kaputt.ino line 48
0x40209018: loop_wrapper() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 177

@SvenSiwek
Copy link
Author

To explain what I do. Playing a song on my PC with this python( It's always the same song to reproduce the error - Carol of The Bells by Tommee Profitt ).

Tested with 30Hz sending. It almost made it, but:

Decoding stack results
0x40100198: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 160
0x40208ee6: can_yield() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 94
0x40208f5f: optimistic_yield(uint32_t) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 128
0x40206f97: Print::write(char const*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/Print.h line 56
0x4020715c: Print::print(char const*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\Print.cpp line 122
0x40206be8: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/HardwareSerial.h line 164
0x40206bf4: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/HardwareSerial.h line 165
0x40206be8: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/HardwareSerial.h line 164
0x40206fbd: Print::write(char const*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/Print.h line 60
0x4020724d: Print::printNumber(unsigned long, unsigned char) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\Print.cpp line 260
0x40208f3a: __yield() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 100
0x40208f5f: optimistic_yield(uint32_t) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 128
0x4020614a: WiFiServer::available(unsigned char*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\WiFiServer.cpp line 120
0x40100a17: free(void*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 362
0x40206be8: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/HardwareSerial.h line 164
0x4020aa04: WiFiClient::operator bool() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\WiFiClient.cpp line 350
0x40204599: esp8266webserver::ESP8266WebServerTemplate ::handleClient() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h line 307
0x40208f5f: optimistic_yield(uint32_t) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 128
0x40100198: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 160
0x402046a9: loop() at D:\Users\svens\Documents\Arduino\udp_kaputt/udp_kaputt.ino line 73
0x40209020: loop_wrapper() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 180

@SvenSiwek
Copy link
Author

Whoops:
After pressing the reset button that happend:
Decoding stack results
0x40100198: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 160
0x401001b9: esp_schedule() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 113
0x40209029: loop_wrapper() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 182

25Hz:

Decoding stack results
0x402170a4: udp_input at core/udp.c line 404
0x4021bfd8: ip4_input at core/ipv4/ip4.c line 1461
0x40100a17: free(void*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 362
0x40212f45: ethernet_input_LWIP2 at netif/ethernet.c line 188
0x40212d68: esp2glue_ethernet_input at glue-lwip/lwip-git.c line 469
0x40232ec2: ethernet_input at glue-esp/lwip-esp.c line 365
0x40232ed3: ethernet_input at glue-esp/lwip-esp.c line 373
0x40210ce2: __ssputs_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 233
0x40100198: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 160
0x40100198: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 160
0x40100198: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 160
0x40100198: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 160
0x40100198: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 160
0x40100198: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 160
0x4020a9ec: WiFiClient::connected() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\WiFiClient.cpp line 338
0x4020aa04: WiFiClient::operator bool() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\WiFiClient.cpp line 350
0x40209f71: uart_write(uart_t*, char const*, size_t) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\uart.cpp line 509
0x40206be8: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/HardwareSerial.h line 164
0x40206bf4: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/HardwareSerial.h line 165
0x40206be8: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/HardwareSerial.h line 164
0x40206fbd: Print::write(char const*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/Print.h line 60
0x4020724d: Print::printNumber(unsigned long, unsigned char) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\Print.cpp line 260
0x40208f3a: __yield() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 100
0x40208f5f: optimistic_yield(uint32_t) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 128
0x4020614a: WiFiServer::available(unsigned char*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\WiFiServer.cpp line 120
0x40100a17: free(void*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 362
0x40206be8: HardwareSerial::write(unsigned char const*, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266/HardwareSerial.h line 164
0x4020aa04: WiFiClient::operator bool() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\WiFiClient.cpp line 350
0x40204599: esp8266webserver::ESP8266WebServerTemplate ::handleClient() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WebServer\src/ESP8266WebServer-impl.h line 307
0x40208f5f: optimistic_yield(uint32_t) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 128
0x40100198: ets_post(uint8, ETSSignal, ETSParam) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 160
0x401001b9: esp_schedule() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 113
0x40209029: loop_wrapper() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 182

And an other one:

Decoding stack results
0x40100a17: free(void*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 362
0x40212f45: ethernet_input_LWIP2 at netif/ethernet.c line 188
0x40212d68: esp2glue_ethernet_input at glue-lwip/lwip-git.c line 469
0x40232ec2: ethernet_input at glue-esp/lwip-esp.c line 365
0x40232ed3: ethernet_input at glue-esp/lwip-esp.c line 373
0x40100384: vPortFree(void*, char const*, int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\heap.cpp line 308
0x40210ce2: __ssputs_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 233
0x40210ce2: __ssputs_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 233
0x40210c18: __ssputs_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 180
0x4020ceb8: _printf_i at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf_i.c line 244
0x40210ce2: __ssputs_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 233
0x40210ecc: _svfprintf_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf.c line 531
0x4020e631: _vsnprintf_r at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/vsnprintf.c line 73
0x4010078c: umm_free_core(void*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 316
0x40100a17: free(void*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\umm_malloc\umm_malloc.cpp line 362
0x40100384: vPortFree(void*, char const*, int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\heap.cpp line 308
0x40209f71: uart_write(uart_t*, char const*, size_t) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\uart.cpp line 509
0x40207f2c: String::copy(char const*, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\WString.cpp line 214
0x40207f62: String::String(char const*) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\WString.cpp line 36
0x4020524d: ESP8266WiFiSTAClass::SSID() const at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 659
0x40205268: ESP8266WiFiSTAClass::SSID() const at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 662
0x4020ca66: _printf_common at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf_i.c line 102
0x4020c81c: _printf_float at /home/earle/src/esp-quick-toolchain/repo/newlib/newlib/libc/stdio/nano-vfprintf_float.c line 327
0x402018fc: esp8266webserver::ESP8266WebServerTemplate ::_parseForm(WiFiClient&, String const&, unsigned int) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WebServer\src/Parsing-impl.h line 396
0x40204f30: ESP8266WiFiSTAClass::config(IPAddress, IPAddress, IPAddress, IPAddress, IPAddress) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 332
0x40204f30: ESP8266WiFiSTAClass::config(IPAddress, IPAddress, IPAddress, IPAddress, IPAddress) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 332
0x40204f30: ESP8266WiFiSTAClass::config(IPAddress, IPAddress, IPAddress, IPAddress, IPAddress) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi\src\ESP8266WiFiSTA.cpp line 332
0x40208f08: __esp_yield() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 100
0x40209516: __delay(unsigned long) at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_wiring.cpp line 54
0x40203751: setup() at D:\Users\svens\Documents\Arduino\udp_kaputt/udp_kaputt.ino line 48
0x40209018: loop_wrapper() at C:\Users\svens\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\cores\esp8266\core_esp8266_main.cpp line 177

@d-a-v
Copy link
Collaborator

d-a-v commented Nov 28, 2019

There is a debug option called OOM
I run the UDP example sketch and flooded it:

while true; do echo hey; done | nc -u 10.0.1.225 8888

I got on console the following (see below).
See the :oom(nnn) messages starting just before the crash.
When it happens, free heap is below 2KB.

I think we should have some sanity barrier for largest umm free chunk block to not be crossed by the core when possible (here we'd drop the incoming flooding packets) (so the FW does not fail like it is the case here according to the :oom messages not coming from us).

The thing is it has a cost to (re)process the largest free block (or the total free heap).
I wonder @mhightower83 if there could be a way to maintain at little cost some sort of cache for the heap metrics (or at least the largest block).
I had not followed the latest umm discussion so I ask here where it would be useful to have.

22:33:23.666 -> Received packet of size 12 from 10.0.1.7:40953
22:33:23.699 ->     (to 10.0.1.225:8888, free heap = 2160 B)
22:33:23.699 -> Contents:(2160)
22:33:23.699 -> hey
22:33:23.699 -> hey
22:33:23.699 -> hey
22:33:23.699 -> 
22:33:23.699 -> Received packet of size 8 from 10.0.1.7:40953
22:33:23.699 ->     (to 10.0.1.225:8888, free heap = 2016 B)
22:33:23.699 -> Contents:(2016)
22:33:23.699 -> hey
22:33:23.699 -> hey
22:33:23.699 -> 
22:33:23.699 -> :oom(124)@?
22:33:23.699 -> Received packet of size 8 from 10.0.1.7:40953
22:33:23.699 ->     (to 10.0.1.225:8888, free heap = 1872 B)
22:33:23.699 -> Contents:(1872)
22:33:23.732 -> hey
22:33:23.732 -> hey
22:33:23.732 -> 
22:33:23.732 -> :oom(236)@?
22:33:23.732 -> Received packet of size 8 from 10.0.1.7:40953
22:33:23.732 ->     (to 10.0.1.225:8888, free heap = 1888 B)
22:33:23.732 -> Contents:(1888)
22:33:23.732 -> hey
22:33:23.732 -> hey
22:33:23.732 -> 
22:33:23.732 -> :oom(236)@?
22:33:23.732 -> :oom(212)@ieee80211_phy.c:313
22:33:23.732 -> Fatal exception 29(StoreProhibitedCause):
22:33:23.732 -> epc1=0x4000df64, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
22:33:23.732 -> 
22:33:23.732 -> Exception (29):
22:33:23.732 -> epc1=0x4000df64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
22:33:23.765 -> 
22:33:23.765 -> >>>stack>>>

@d-a-v
Copy link
Collaborator

d-a-v commented Nov 28, 2019

More interestingly, I replaced getFreeHeap() by getMaxFreeBlockSize() right next to the Content: message.
When we can, we really should prevent the core and the FW from agonizing when max-free-blocksize is that low.

23:01:41.453 -> hey
23:01:41.453 -> hey
23:01:41.453 -> hey
23:01:41.453 -> 
23:01:41.453 -> :oom(236)@?
23:01:41.453 -> :oom(108)@?
23:01:41.453 -> :oom(1532)@?
23:01:41.486 -> :oom(1532)@?
23:01:41.486 -> Received packet of size 4 from 10.0.1.7:37742
23:01:41.486 ->     (to 10.0.1.225:8888, free heap = 1856 B)
23:01:41.486 -> Contents:(224)
23:01:41.486 -> hey
23:01:41.486 -> 
23:01:41.486 -> :oom(236)@?
23:01:41.486 -> :oom(1532)@?
23:01:41.486 -> Received packet of size 4 from 10.0.1.7:37742
23:01:41.486 ->     (to 10.0.1.225:8888, free heap = 2008 B)
23:01:41.486 -> Contents:(200)
23:01:41.486 -> hey
23:01:41.486 -> 
23:01:41.486 -> :oom(236)@?
23:01:41.486 -> Received packet of size 8 from 10.0.1.7:37742
23:01:41.520 ->     (to 10.0.1.225:8888, free heap = 1728 B)
23:01:41.520 -> Contents:(144)
23:01:41.520 -> hey
23:01:41.520 -> hey
23:01:41.520 -> 
23:01:41.520 -> :oom(236)@?
23:01:41.520 -> Received packet of size 4 from 10.0.1.7:37742
23:01:41.520 ->     (to 10.0.1.225:8888, free heap = 1728 B)
23:01:41.520 -> Contents:(152)
23:01:41.520 -> hey
23:01:41.520 -> 
23:01:41.520 -> :oom(236)@?
23:01:41.520 -> :oom(68)@?
23:01:41.520 -> :oom(40)@?
23:01:41.520 -> :oom(92)@abi.cpp:48
23:01:41.520 -> Contents:(80)
23:01:41.520 -> hey
23:01:41.520 -> 
23:01:41.520 -> :oom(236)@?
23:01:41.553 -> :oom(108)@?
23:01:41.553 -> Received packet of size 8 from 10.0.1.7:37742
23:01:41.553 ->     (to 10.0.1.225:8888, free heap = 1944 B)
23:01:41.553 -> Contents:(192)
23:01:41.553 -> hey
23:01:41.553 -> hey
23:01:41.553 -> 
23:01:41.553 -> :oom(236)@?
23:01:41.553 -> :oom(1532)@?
23:01:41.553 -> :oom(68)@?
23:01:41.553 -> Received packet of size 8 from 10.0.1.7:37742
23:01:41.553 ->     (to 10.0.1.225:8888, free heap = 1800 B)
23:01:41.553 -> Contents:(224)
23:01:41.553 -> hey
23:01:41.553 -> hey
23:01:41.553 -> 
23:01:41.553 -> :oom(236)@?
23:01:41.553 -> :oom(100)@?
23:01:41.553 -> Received packet of size 4 from 10.0.1.7:37742
23:01:41.586 ->     (to 10.0.1.225:8888, free heap = 1944 B)
23:01:41.586 -> Contents:(320)
23:01:41.586 -> hey
23:01:41.586 -> 
23:01:41.586 -> :oom(124)@?
23:01:41.586 -> :oom(1532)@?
23:01:41.586 -> :oom(1532)@?
23:01:41.586 -> Received packet of size 8 from 10.0.1.7:37742
23:01:41.586 ->     (to 10.0.1.225:8888, free heap = 1792 B)
23:01:41.586 -> Contents:(144)
23:01:41.586 -> hey
23:01:41.586 -> hey
23:01:41.586 -> 
23:01:41.586 -> :oom(236)@?
23:01:41.586 -> :oom(1532)@?
23:01:41.586 -> :oom(68)@?
23:01:41.586 -> Received packet of size 8 from 10.0.1.7:37742
23:01:41.586 ->     (to 10.0.1.225:8888, free heap = 1792 B)
23:01:41.619 -> Contents:(144)
23:01:41.619 -> hey
23:01:41.619 -> hey
23:01:41.619 -> 
23:01:41.619 -> :oom(236)@?
23:01:41.619 -> :oom(212)@ieee80211_phy.c:313
23:01:41.619 -> Fatal exception 29(StoreProhibitedCause):
23:01:41.619 -> epc1=0x4000df64, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
23:01:41.619 -> 
23:01:41.619 -> Exception (29):
23:01:41.619 -> epc1=0x4000df64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
23:01:41.619 -> 
23:01:41.619 -> >>>stack>>>
23:01:41.619 -> 
23:01:41.619 -> ctx: sys
23:01:41.619 -> sp: 3fffec10 end: 3fffffb0 offset: 01a0
23:01:41.619 -> 3fffedb0:  40220113 3ffed778 00000002 402200a8  

@devyte
Copy link
Collaborator

devyte commented Nov 29, 2019

@SvenSiwek Now that is a good MCVE. It might even serve as a device test.

Alright, we've been discussing internally, here's a summary.
What we had before was no buffering: if a packet arrived, and wasn't received by the app fast enough, then receiving the next packet meant overwriting the current one, thereby dropping it. There was some bug on top of that. The behavior was not enough for some applications.
That was changed to do full buffering, which means every packet received would get queued. The responsability for dropping packets was thereby shifted to the user. The current state seems to be that the incoming packet rate is faster than the ability to pass the packets to the user app. I seem to remember that wasn't the case before, but it seems to be the case now. This also doesn't work because it allows DoS type flooding of the ESP causing it to fail.
The solution must then be an intermediate: do limited buffering.

Possible Solutions:

  1. Keep a packet counter across all udp queues. Drop packets if total count is above some max. For max ==1 you get the solution before the mentioned fix. For max some huge number, you get the current solution. Con: count doesn't take fragmentation into account.
  2. Keep a total size across all packets across all udp queues. Drop packets if total size is above some max. Con: doesn't take available free heap into account.
  3. Check available heap. Drop packets if available heap is below some min. Pro: simple to implement Con: doesn't take differing free mem requirements for different apps into account.
  4. Keep a total size across all packets across all udp queues. Drop packets if total size is significant against available heap. Pro: most flexible. Con: more complex to implement. This is essentially a combination of 2 and 3 above.

@TD-er
Copy link
Contributor

TD-er commented Nov 29, 2019

  1. Separate drop/queue rules per port for the UDP. For example: drop newest packets when received on port X, drop oldest packets when received on port Y.

@SvenSiwek
Copy link
Author

Hi there :)
What was the origin to implement a buffer for UDP ?
The UDP protocoll was invented/implemented with the idea of possible packet loss.

If I wanted to be sure to receive all packets I have to use TCP/IP .

So, please forgive me ... I do not understand the whole buffering concept here.

If you still want buffering - make it transparent to the sketch:

You can determine size of that buffer in the sketch and what should happen if the buffer is full.
Ignore new packets arring, or dismiss the oldest in the buffer....

One single question: If I understood you right, an interal buffer was flooded.
Why I can't see that with the int packetSize = port.parsePacket(); ?

I never saw a value > 500 in the output of my MCVE

have a nice weekend
Sven

@TD-er
Copy link
Contributor

TD-er commented Nov 29, 2019

The buffer keeps multiple packets. So it is not a buffer issue for a single packet.

@SvenSiwek
Copy link
Author

The buffer keeps multiple packets. So it is not a buffer issue for a single packet.

the penny dropped

@d-a-v
Copy link
Collaborator

d-a-v commented Nov 29, 2019

What was the origin to implement a buffer for UDP ?

The network stack receives data while your sketch is doing something else, so packet data need to be buffered until sketches ask for them.

If you still want buffering - make it transparent to the sketch:

It already is

Ignore new packets arring, or dismiss the oldest in the buffer....

I'm not sure this kind of setting is good on the arduino side. The same question was asked for serial data. What to do when the input buffer is full?, and the answer was not clear (currently new data are discarded when buffer is full).

Why I can't see that with the int packetSize = port.parsePacket(); ?

Because you see the oldest first.

@devyte
Copy link
Collaborator

devyte commented Nov 29, 2019

By buffer I really mean a packet list.
The ESP has a somewhat unsmooth way of processing things. Received packets are stored until the sketch asks for them. At this point the sketch is expected to get all packets possible.
There was a case where a stream of packets was resulting in drops for no good reason. The buffering implemented was meant to simply allow the user to receive the packets despite possibly processing peaks. The point was: packets may be lost, but let's at least not have the core be the cause. Either lose them in transit, or have the user app make the decision not to process some of them.
As I mentioned, I seem to remember testing at some point that the packet throughput could be handled by the processor. Given your MCVE, that seems to not hold now => packet list grows and eats up all heap. This likely should be investigated further, the esp has plenty of processing power, so seeing it not able to keep up in your MCVE surprises me.
In any case, a cap on the packet list does make sense. The specifics is still up for discussion.

@devyte devyte closed this as completed Nov 29, 2019
@devyte devyte reopened this Nov 29, 2019
@TD-er
Copy link
Contributor

TD-er commented Nov 29, 2019

so seeing it not able to keep up in your MCVE surprises me.

In the loop() call a lot is written to serial port.
If the buffer of the serial port is full, writing to it will become blocking.
So maybe only aggregate the counts of packets and only print a counter every second, or maybe every 100 packets?

@mhightower83
Copy link
Contributor

@d-a-v Sorry for the delay. I cannot see a low-cost way to do that. Any largest chunk of memory you have cached can shrink through having additional new allocations carved from it until it is smaller than one of the other free blocks that were not in your large free list cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants