Skip to content

Crash and reboot when reaching getString() method #6688

@MateuszManaj

Description

@MateuszManaj

Basic Infos

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

Platform

  • Hardware: [nodeMCU dev board rev3]
  • Core Version: 2.5.2 (from added logs)
  • Development Env: [Arduino IDE]
  • Operating System: [MacOS]

Settings in IDE

  • Module: [Nodemcu]
  • Flash Mode: [don't know]
  • Flash Size: [4MB]
  • lwip Variant: [v2 Lower Memory]
  • Reset Method: [nodemcu]
  • Flash Frequency: [40Mhz]
  • CPU Frequency: [80Mhz]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200] (serial upload only)

Problem Description

Board crashed when code reaching

String payload = http.getString();

Problem occurs when requesting GET from this host: http://192.168.8.218 - this is my stove webserver. For 1 month it was ok but now i cannot getting response. Other host working properly. I tried to change IP of webserver - nothing changed.

Tell me, what needs to happen for getString() method to crash and reboot board ?
In addtion, response from webserver is correct. All packets and whole response is ok.

MCVE Sketch

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#include <WiFiClient.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {

  Serial.begin(115200);
  // Serial.setDebugOutput(true);

  Serial.println();
  Serial.println();
  Serial.println();

  for (uint8_t t = 4; t > 0; t--) {
    Serial.printf("[SETUP] WAIT %d...\n", t);
    Serial.flush();
    delay(1000);
  }

  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP("ABC", "DEF");

}

void loop() {
  // wait for WiFi connection
  if ((WiFiMulti.run() == WL_CONNECTED)) {

    WiFiClient client;

    HTTPClient http;

    Serial.print("[HTTP] begin...\n");
    if (http.begin(client, "http://192.168.8.218")) {  // HTTP


      Serial.print("[HTTP] GET...\n");
      // start connection and send HTTP header
      int httpCode = http.GET();

      // httpCode will be negative on error
      if (httpCode > 0) {
        // HTTP header has been send and Server response header has been handled
        Serial.printf("[HTTP] GET... code: %d\n", httpCode);

        // file found at server
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
          String payload = http.getString();
          Serial.println(payload);
        }
      } else {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
      }

      http.end();
    } else {
      Serial.printf("[HTTP} Unable to connect\n");
    }
  }

  delay(10000);
}

Debug Messages

Decoding stack results
0x4021850c: mem_malloc at core/mem.c line 210
0x40206e3c: malloc(size_t) at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/umm_malloc/umm_malloc.cpp line 1677
0x40210fac: lwip_cyclic_timer at core/timeouts.c line 233
0x4021850c: mem_malloc at core/mem.c line 210
0x4020f8e8: do_memp_malloc_pool at core/memp.c line 254
0x4020f924: memp_malloc at core/memp.c line 356
0x40210f51: sys_timeout_abs at core/timeouts.c line 189
0x40210fac: lwip_cyclic_timer at core/timeouts.c line 233
0x40210fdf: lwip_cyclic_timer at core/timeouts.c line 261
0x4020f94e: memp_free at core/memp.c line 447
0x40211154: sys_check_timeouts at core/timeouts.c line 390
0x4020551f: loop_task(ETSEvent*) at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/core_esp8266_main.cpp line 133
0x4020f221: glue2esp_linkoutput at glue-esp/lwip-esp.c line 299
0x4020f4a3: new_linkoutput at glue-lwip/lwip-git.c line 235
0x4020f894: ethernet_output at netif/ethernet.c line 312
0x4021702c: etharp_output_LWIP2 at core/ipv4/etharp.c line 885
0x4020555a: esp_yield() at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/core_esp8266_main.cpp line 88
0x40213dfd: tcp_output_alloc_header at core/tcp_out.c line 1863
0x40214750: tcp_send_empty_ack at core/tcp_out.c line 2057
0x4021483e: tcp_output at core/tcp_out.c line 1319
0x402046c4: String::copy(char const*, unsigned int) at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/WString.cpp line 211
0x40205564: esp_yield() at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/core_esp8266_main.cpp line 91
0x40205564: esp_yield() at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/core_esp8266_main.cpp line 91
0x40205646: __yield() at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/core_esp8266_main.cpp line 100
0x4020430d: Stream::timedRead() at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/Stream.cpp line 37
0x4020434b: Stream::readBytes(char*, unsigned int) at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/Stream.cpp line 211
0x40207380: Stream::readBytes(unsigned char*, unsigned int) at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/Stream.h line 92
0x40203528: HTTPClient::writeToStreamDataBlock(Stream*, int) at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp line 1376
0x402035b0: HTTPClient::writeToStream(Stream*) at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp line 925
0x40204704: String::String(char const*) at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/WString.cpp line 36
0x40203d7e: HTTPClient::getString() at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp line 1010
0x4020117f: loop() at /Users/mateuszmanaj/Documents/Arduino/BasicHttpClient/BasicHttpClient.ino line 62
0x402018ac: ESP8266WiFiMulti::addAP(char const*, char const*) at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp line 39
0x40205614: loop_wrapper() at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/cores/esp8266/core_esp8266_main.cpp line 125

Activity

devyte

devyte commented on Oct 29, 2019

@devyte
Collaborator

[] If there is a stack dump, I have decoded it.

Why isn't the stack decoded? Please decode it and add it above.

MateuszManaj

MateuszManaj commented on Oct 29, 2019

@MateuszManaj
Author

I do not know how :)

devyte

devyte commented on Oct 29, 2019

@devyte
Collaborator

Just google "decode esp8266 stack". Also, readthedocs.

MateuszManaj

MateuszManaj commented on Oct 29, 2019

@MateuszManaj
Author

Ok, thank you. I edited issue. Is this memory leak ?

devyte

devyte commented on Oct 29, 2019

@devyte
Collaborator

You said:

[x] I have tested that the issue is present in current master branch (aka latest git).

But from your stack dump, you're using core v2.5.2.

Retesting with latest git is needed before this can be looked at further, because there have been several issues fixed, including interrupt and String issues. In other words, it makes no sense to look at this if the issue is already fixed in the latest code base.

Instructions for installing latest git are in readthedocs.

I am closing for now. If you find more information, please post it here and we can continue to discuss.

MateuszManaj

MateuszManaj commented on Oct 30, 2019

@MateuszManaj
Author

@devyte ok, thank you for instructions.
I've updated already ESP8266 lib and there is my another decoded exception stack:

Decoding stack results
0x40217314: ip4_output_if_opt_src at core/ipv4/ip4.c line 1764
0x401008e8: malloc(size_t) at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/cores/esp8266/umm_malloc/umm_malloc.cpp line 511
0x40217e10: mem_malloc at core/mem.c line 210
0x40211d54: pbuf_alloc_LWIP2 at core/pbuf.c line 284
0x40212805: tcp_output_alloc_header_common at core/tcp_out.c line 1825
0x402128c9: tcp_output_alloc_header at core/tcp_out.c line 1863
0x402131f2: tcp_send_empty_ack at core/tcp_out.c line 2042
0x4021330a: tcp_output at core/tcp_out.c line 1319
0x40100154: ets_post(uint8, ETSSignal, ETSParam) at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_main.cpp line 156
0x4020e57d: tcp_recved at core/tcp.c line 1003
0x40202ba4: ClientContext::_consume(unsigned int) at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/include/ClientContext.h line 556
0x40202c1a: WiFiClient::read() at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/include/ClientContext.h line 239
0x402047fc: Stream::timedRead() at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Stream.cpp line 34
0x4020484b: Stream::readBytes(char*, unsigned int) at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Stream.cpp line 215
0x40207590: Stream::readBytes(unsigned char*, unsigned int) at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/cores/esp8266/Stream.h line 92
0x4020373c: HTTPClient::writeToStreamDataBlock(Stream*, int) at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp line 1401
0x4020416f: HTTPClient::sendRequest(char const*, unsigned char*, unsigned int) at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp line 725
0x402037be: HTTPClient::writeToStream(Stream*) at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp line 934
0x40204262: HTTPClient::getString() at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp line 1019
0x40201180: loop() at /Users/mateuszmanaj/Documents/Arduino/BasicHttpClient/BasicHttpClient.ino line 62
0x40201abb: std::vector   >::_M_emplace_back_aux (WifiAPEntry const&) at /Users/mateuszmanaj/Library/Arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-3-20ed2b9/xtensa-lx106-elf/include/c++/4.8.2/ext/new_allocator.h line 104
0x40201bc0: ESP8266WiFiMulti::addAP(char const*, char const*) at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.cpp line 39
0x40205c90: loop_wrapper() at /Users/mateuszmanaj/Documents/Arduino/hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_main.cpp line 176

Can you help me with this ?

devyte

devyte commented on Oct 30, 2019

@devyte
Collaborator

How big is the resource you're trying to GET?

MateuszManaj

MateuszManaj commented on Oct 30, 2019

@MateuszManaj
Author

It's very small ~25kb

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
	<meta HTTP-EQUIV="content-type" content="text/html; charset=utf-8" />
	<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
	<meta name="handheldFriendly" content="true" />              
	<meta name="viewport" content="width=device-width; initial-scale=1"; user-scalable="yes" />
	
	<title>MultiFun Control System</title>
	<link ID="styl_id" rel="stylesheet" type="text/css" media="screen"/> <!--href="style.css"-->
	<script language="javascript">
		var szer = window.screen.width;
		if(navigator.userAgent.indexOf('Opera Mini') > -1)
		{
			if(szer <= 1024){ document.getElementById('styl_id').href = "opmini.css"; }
			else{ document.getElementById('styl_id').href = "style.css"; }
		}
		else
		{
			if(szer <= 800) {document.getElementById('styl_id').href = "styleh.css"; }
			else if(szer <= 1024){document.getElementById('styl_id').href = "style600.css";}
			else{document.getElementById('styl_id').href = "style.css";}
		}
	</script>
</head>
<body>
	<div id="glowny">
		<div id="obrazek">
			<div id="ziel"><h1 class="green">MultiFun Control System</h1></div>
			<!--temperatury od róry-->
			<!--spaliny-->
			<div id="spaliny"><h1 class="black">32</h1></div>
			<!--zewnętrzna-->
			<div id="zewnetrzna"><h1 style="font-size: 42px;" class="blue"></h1></div>
			<!--pokojowa1-->
			<div id="pokojowa1"><h1 class="cherry"></h1></div>
			<!--pokojowa2-->
			<div id="pokojowa2"><h1 class="cherry"></h1></div>
			<!--CO1-->
			<div id="CO1"><h1 class="red">23</h1></div>
			<!--CO2-->
			<div id="CO2"><h1 class="red">26</h1></div>
			<!--Kocioł-->
			<div id="kociol"><h1 class="red">34</h1></div>
			<!--CWU-->
			<div id="CWU"><h1 class="red">37</h1></div>
			<!--Wyliczone-->
			<!--Pokój 1-->
			<div id="pokoj1"><h2></h2></div>
			<!--Pokój 2-->
			<div id="pokoj2"><h2></h2></div>
			<!--CO 1-->
			<div id="WCO1"><h2>20</h2></div>
			<!--CO 2-->
			<div id="WCO2"><h2></h2></div>
			<!--Kotla-->
			<div id="WKOC"><h2>0</h2></div>
			<!--CWU-->
			<div id="WCWU"><h2>0</h2></div>
			<form method="get" action="/opts.cgi">
				<div id="th1"><input type="text" name="TH1" size="4" value="35"></div>
				<div id="th2"><input type="text" name="TH2" size="4" value=""></div>
				<div id="th3"><input type="text" name="TH3" size="4" value="45"></div>
				<div id="op1"><input value="1" name="op" type="checkbox"></div>
				<div id="op2"><input value="2" name="op" type="checkbox"></div>
				<div id="op3"><input value="3" name="op" type="checkbox"></div>
				<div id="op4"><input value="4" name="op" type="checkbox"></div>
				<div id="op5"><input value="5" name="op" type="checkbox"></div>
				<div id="pas"><input name="pass" size="4" type="password"></div>
				<div id="but"><input value="OK" type="submit"></div>
			</form>
		</div>
	</div>
</body>
</html>
MateuszManaj

MateuszManaj commented on Oct 30, 2019

@MateuszManaj
Author

I must add that this module works perfectly for about 2-3 months and suddenly stopped working (of course on previous git version of board). I tested this code on other same nodeMCU's but nothing change. This is very strange.
The only thing could change is my stove webserver but i do not see any strange notation or differencies. Also head od this document is ok. There is no special signs in code and encoding is UTF-8 wo. BOM.

devyte

devyte commented on Oct 30, 2019

@devyte
Collaborator

25KB is most definitely NOT very small, it's about half the total amount of available heap of an empty sketch, and yours is not an empty sketch.
My guess is you're oom. Please check available heap right before the call to getString().

MateuszManaj

MateuszManaj commented on Oct 30, 2019

@MateuszManaj
Author

25KB is most definitely NOT very small, it's about half the total amount of available heap of an empty sketch, and yours is not an empty sketch.
My guess is you're oom. Please check available heap right before the call to getString().

Sorry, it's 2.9 - 3.1 kb.
What OOM stands for ?

MateuszManaj

MateuszManaj commented on Oct 30, 2019

@MateuszManaj
Author

Ok, I have Exception 3 which stands for: LoadStoreErrorCause
Processor internal physical address or data error during load or store
Free heap before getString() is: 50864

devyte

devyte commented on Oct 30, 2019

@devyte
Collaborator

3KB should be ok, then I don't think it's oom (out of memory).
I think the only thing missing are the headers sent with your resource. Can you figure out how to get them and post them here? I think that should be enough info for someone to investigate.

MateuszManaj

MateuszManaj commented on Oct 30, 2019

@MateuszManaj
Author

Response Headers:

HTTP/1.0 200 OK
Server: lwIP/1.3.1 (http://savannah.nongnu.org/projects/lwip)
Content-type: text/html
Expires: Fri, 10 Apr 2008 14:00:00 GMT
Pragma: no-cache

Maybe you reopen this issue ?

19 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Crash and reboot when reaching getString() method · Issue #6688 · esp8266/Arduino