These are chat archives for esp8266/Arduino

4th
Apr 2016
Ivan Grokhotkov
@igrr
Apr 04 2016 07:43
@andig @me-no-dev the case in the stack trace posted above looks pretty clear:
• AsyncClient gets TCP close event and aborts the connection ESPAsyncTCP.cpp#L241
• tcp_close returns some kind of error (for whatever reason, doesn't really matter) and the code goes down the path of calling abort()ESPAsyncTCP.cpp#L194
• tcp_abort calls error callback with error code ERR_ABRT (via tcp_abandon) tcp.c#L398
• we are in trouble already, because pcb has been destroyed, but we are trying to adjust the value of state, i.e. writing some structure which has been deallocated. ESPAsyncTCP.cpp#L222
• error callback calls discard_cb ESPAsyncTCP.cpp#L225
• this calls AsyncWebServerRequest::onDisconnect, which does delete client; WebRequest.cpp#L180
• from there we go into AsyncClient destructor, which calls tcp_abort again ESPAsyncTCP.cpp#L81
From the first look, i think it might be sufficient to set _pcb to zero before calling tcp_abort.
but it might break something else (i haven't read all the async code yet)
Stavros Korokithakis
@skorokithakis
Apr 04 2016 11:24
has anyone done anything with GSM?
Stavros Korokithakis
@skorokithakis
Apr 04 2016 12:36
behold, my wifi led strip controller: https://i.imgur.com/HELEQZm.jpg
tzapu
@tzapu
Apr 04 2016 13:03
:thumbsup: looking nice
sticilface
@sticilface
Apr 04 2016 14:06
This message was deleted
Got a question for the boffins. I'm trying to optimise memory and I've found something that I'm not so sure about.... I'm using the HTTPClient lib. And by compiling with the GET() function I loose around 5K of free memory, straight off! Just by including a call to this function... does this sound right? I'd have thought that the required networking stuff would already be in there seeing as the HTTPserver is included etc... this happens on the basic HTTPClient example too... just seems like an awful lot of RAM!
sticilface
@sticilface
Apr 04 2016 14:22
@skorokithakis looks good! is that a PWM controlled strip? looks like it, have you tried WS2812s?
Stavros Korokithakis
@skorokithakis
Apr 04 2016 14:23
@sticilface it is, i haven't tried that because it's rather more expensive than plain 5050s
but i should
sticilface
@sticilface
Apr 04 2016 14:28
How are you driving them? I think the native PWM out, is a little unreliable on the ESP
Ivan Grokhotkov
@igrr
Apr 04 2016 14:32
@sticilface lots of strings in HTTPClient lib, i bet most may be wrapped into F() macro
sticilface
@sticilface
Apr 04 2016 14:33
5K worth though?... I did have a look, but could not see anything obvious...
I'll F() them and see what happens
Stavros Korokithakis
@skorokithakis
Apr 04 2016 14:38
@sticilface pwm, yeah. seems reliable enough, what did you find unreliable?
sticilface
@sticilface
Apr 04 2016 14:40
ah cool... i've never tried them, just the WS2812s.. as i was interested in animations and such.. just read various places that the PWM would be flickery...
Stavros Korokithakis
@skorokithakis
Apr 04 2016 14:40
ah, hmm, seems fine here
sticilface
@sticilface
Apr 04 2016 14:58
Ah found it...
@igrr the httpclient uses the https stuff, so even if you don't use it, or include it... it will take 6k of your heap.. I think this should be changed.. no? if i comment out lines 733-740 and 757-765 I regain the heap ..
sticilface
@sticilface
Apr 04 2016 15:07
it is quite tightly integrated though... maybe an HTTPclient and an HTTPSclient?
Ivan Grokhotkov
@igrr
Apr 04 2016 15:14
@sticilface You are right. This is possible to fix, but requires some refactoring of HTTPClient.
HTTP/S can be split so that linker will throw out unused stuff
sticilface
@sticilface
Apr 04 2016 15:17
That would be beyond my pay grade... linker stuff... but it is just the two calls _tcps = new WiFiClientSecure(); and _tcps->verify(_httpsFingerprint.c_str() that seem to do it.
sticilface
@sticilface
Apr 04 2016 15:30
I shall make an issue...
sticilface
@sticilface
Apr 04 2016 16:24
done esp8266/Arduino#1855
ZaPpInG
@lrmoreno007
Apr 04 2016 17:45
Somebody try Eclipse Arduino?
Now is very easy to install with Eclipse Arduino v3
:)
1.- Install eclipse
2.- Copy link to Eclipse Arduino Arduino from Baeyens.it
3.- In eclipse open intall new software
andig
@andig
Apr 04 2016 18:53

@igrr, cc @me-no-dev thanks for the detailed analysis. I can follow your in-depth analysis with the use after free but I'm not sure about

From the first look, i think it might be sufficient to set _pcb to zero before calling tcp_abort.

tcp_abort needs the _pcb from what I understand- so I'd habe to set it before calling abort. Tried to put it here:

int8_t AsyncClient::_close(){
int8_t err = ERR_OK;
if(_pcb) {
err = tcp_close(_pcb);
if(err != ERR_OK) {
_pcb = NULL;
err = abort();
}
}
return err;
}

Is that what you've meant? Quickly gets me into the next exception, also feels like a memory leak?

Ivan Grokhotkov
@igrr
Apr 04 2016 19:03
No, of course not that way :)
like
auto pcb = _pcb;
_pcb = nullptr;
tcp_abort(pcb);
that should go into abort() function
(@me-no-dev probably knows better — I'm just guessing here)
andig
@andig
Apr 04 2016 19:05
in this show I'm on the consumer side :worried:
let me test
I see- make sure our local _pcb is zero when the error callback comes in.
andig
@andig
Apr 04 2016 19:13
I guess I'll have to wait for our friend from the async world ;)
0x4022667d: pbuf_alloc at /Users/igrokhotkov/projects/esp8266/esp_iot_sdk_v1.5.2/app/lwip/core/pbuf.c:366
0x4010020c: _umm_free at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:1285
0x401008c8: free at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:1731
0x4010020c: _umm_free at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:1285
0x401071f4: printf at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266/libc_replacements.c:343
0x4010020c: _umm_free at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:1285
0x4010020c: _umm_free at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:1285
0x401008c8: free at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:1731
0x4020ee14: AsyncWebServer::_handleDisconnect(AsyncWebServerRequest*) at c:\andi\arduino\hardware\esp8266com\esp8266\tools\xtensa-lx106-elf\xtensa-lx106-elf\include\c++\4.8.2/functional:2439
0x4010031d: check_poison at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:817
0x4020bd68: operator() at C:\andi\arduino\hardware\esp8266com\esp8266\libraries\ESPAsyncWebServer\src/WebRequest.cpp:568
(inlined by) _M_invoke at c:\andi\arduino\hardware\esp8266com\esp8266\tools\xtensa-lx106-elf\xtensa-lx106-elf\include\c++\4.8.2/functional:2071
0x40100426: check_poison_block at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:851
0x40100466: get_unpoisoned at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:936
0x401008bc: free at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:1718
0x40107154: vPortFree at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266/heap.c:18
0x40228a21: tcp_input at /Users/igrokhotkov/projects/esp8266/esp_iot_sdk_v1.5.2/app/lwip/core/tcp_in.c:362
0x40225afd: ip_input at /Users/igrokhotkov/projects/esp8266/esp_iot_sdk_v1.5.2/app/lwip/core/ipv4/ip.c:559
0x4010020c: _umm_free at C:\andi\arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c:1285
0x40225119: ethernet_input at /Users/igrokhotkov/projects/esp8266/esp_iot_sdk_v1.5.2/app/lwip/netif/etharp.c:1379
0x40105bd6: wdt_feed at ??:?
0x40230db8: ets_timer_handler_isr at ??:?
0x40230dde: ets_timer_handler_isr at ??:?
0x40230a03: ets_snprintf at ??:?
copied here: me-no-dev/ESPAsyncTCP#7
Me No Dev
@me-no-dev
Apr 04 2016 21:04
@andig is this trace with the change @igrr proposed?
Me No Dev
@me-no-dev
Apr 04 2016 21:13
int8_t AsyncClient::_close(){
int8_t err = ERR_OK;
if(_pcb) {
err = tcp_close(_pcb);
if(err == ERR_ABRT) {
_pcb = NULL;
} else if(err != ERR_OK) {
err = abort();
}
}