Skip to content

WifiClientSecure.write does not return error when there is no internet connection #3517

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
odelot opened this issue Aug 14, 2017 · 3 comments
Assignees
Milestone

Comments

@odelot
Copy link

odelot commented Aug 14, 2017

Basic Infos

Hardware

Hardware: ESP-12E
Core Version: 2.4.0-rc1

Description

After I remove the WLAN cable from the router, WifiClientSecure.write continue returning with success (the number of bytes wrote are exactly the number I sent, even with no internet) and the connected method keeps returning true (in the client->state() == ESTABLISHED case). It seems that the write is a non-blocking function (different from core version 2.3.0)

after a while, the write method cannot allocate more memory and crashes. I am using the WifiClientSecure with ArduinoWebSockets

Stack

Decoding 30 results
0x401004d8: malloc at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c line 1664
0x4020632c: ClientContext::_write_from_source(DataSource*) at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 615
0x40206e00: ClientContext::write(unsigned char const*, unsigned int) at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 615
:  (inlined by) __ax_port_write at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 644
0x402239bc: send_raw_packet at ssl/tls1.c line 2005
:  (inlined by) send_packet at ssl/tls1.c line 1267
0x40224524: ssl_read at ssl/tls1.c line 2005
0x40212256: optimistic_yield at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266/core_esp8266_main.cpp line 57
0x40223a48: ssl_write at ssl/tls1.c line 2005
0x40209abe: WebSockets::sendFrame(WSclient_t*, WSopcode_t, unsigned char*, unsigned int, bool, bool, bool) at C:\Users\fabio\Documents\Arduino\libraries\arduinoWebSockets\src/WebSockets.cpp line 97
0x40206880: WiFiClientSecure::write(unsigned char const*, unsigned int) at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\libraries\ESP8266WiFi\src/WiFiClientSecure.cpp line 615
0x40209bce: WebSockets::sendFrame(WSclient_t*, WSopcode_t, unsigned char*, unsigned int, bool, bool, bool) at C:\Users\fabio\Documents\Arduino\libraries\arduinoWebSockets\src/WebSockets.cpp line 241
0x40101f90: wDev_ProcessFiq at ?? line ?
0x4020a76c: WebSocketsClient::sendBIN(unsigned char*, unsigned int, bool) at C:\Users\fabio\Documents\Arduino\libraries\arduinoWebSockets\src/WebSocketsClient.cpp line 263
0x4010053d: _umm_realloc at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c line 1491
:  (inlined by) realloc at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c line 1709
0x402121ac: esp_yield at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266/core_esp8266_main.cpp line 57
0x4020a78c: WebSocketsClient::sendBIN(unsigned char const*, unsigned int) at C:\Users\fabio\Documents\Arduino\libraries\arduinoWebSockets\src/WebSocketsClient.cpp line 263
0x4020b298: AWSWebSocketClient::write(unsigned char const*, unsigned int) at C:\Users\fabio\Documents\Arduino\libraries\aws-mqtt-websockets/AWSWebSocketClient.cpp line 476
0x40203521: MQTT::Client ::sendPacket(int, Countdown&) at C:\Users\fabio\Documents\Arduino\libraries\MQTTClient/MQTTClient.h line 328
0x40203a04: MQTT::Client ::publish(int, Countdown&, MQTT::QoS) at C:\Users\fabio\Documents\Arduino\libraries\MQTTClient/MQTTClient.h line 799
0x4010068c: free at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c line 1733
0x40204cdc: MQTT::Client ::publish(char const*, void*, unsigned int, unsigned short&, MQTT::QoS, bool) at C:\Users\fabio\Documents\Arduino\libraries\MQTTClient/MQTTClient.h line 878
:  (inlined by) MQTT::Client ::publish(char const*, void*, unsigned int, MQTT::QoS, bool) at C:\Users\fabio\Documents\Arduino\libraries\MQTTClient/MQTTClient.h line 888
:  (inlined by) MQTT::Client ::publish(char const*, MQTT::Message&) at C:\Users\fabio\Documents\Arduino\libraries\MQTTClient/MQTTClient.h line 895
:  (inlined by) sendmessage(char const*) at C:\Users\fabio\Documents\Arduino\stayintouchinc8/stayintouchinc8.ino line 487
0x4010020c: _umm_free at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c line 1287
0x4010068c: free at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266\umm_malloc/umm_malloc.c line 1733
0x40204db8: movementStatusMessage(bool) at C:\Users\fabio\Documents\Arduino\stayintouchinc8/stayintouchinc8.ino line 524
0x40212904: AWSWebSocketClient::connected() at C:\Users\fabio\Documents\Arduino\libraries\aws-mqtt-websockets/AWSWebSocketClient.cpp line 476
0x40204e20: iotNightLamp() at C:\Users\fabio\Documents\Arduino\stayintouchinc8/stayintouchinc8.ino line 714
0x40204eff: loop at C:\Users\fabio\Documents\Arduino\stayintouchinc8/stayintouchinc8.ino line 822
0x4020346c: setup at C:\Users\fabio\Documents\Arduino\stayintouchinc8/stayintouchinc8.ino line 781
0x402121f8: loop_wrapper at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266/core_esp8266_main.cpp line 57
0x40100714: cont_norm at C:\Program Files (x86)\Arduino\hardware\esp8266com\esp8266\cores\esp8266/cont.S line 109
@odelot odelot changed the title WifiClientSecure seems to not disconnect WifiClientSecure.write does not return error when connection is lost Aug 14, 2017
@odelot odelot changed the title WifiClientSecure.write does not return error when connection is lost WifiClientSecure.write does not return error when there is no internet connection Aug 15, 2017
@igrr igrr added this to the 2.4.0 milestone Aug 24, 2017
@igrr igrr self-assigned this Aug 24, 2017
@cristovao-trevisan
Copy link

Probably the same as in #3537. There is also a fix that is not fully tested.

@d-a-v
Copy link
Collaborator

d-a-v commented Dec 13, 2017

Probably related to #3957 since memory is full and realloc() is involved.

@earlephilhower
Copy link
Collaborator

Can't reproduce under git head. client.write() seems to fail cleanly when there is no WiFi connection. The crash shown in the report looks like it's a standard OOM under axTLS with a large user app.

Closing as can't reproduce. If you can make a MCVE, please file a new one so we can look at it.

My simple tester (connecting to an openssl s_server):

#include <Arduino.h>
#include <ESP8266WiFi.h>

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.begin("....", "....");
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");

  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  WiFiClientSecure client;
  client.connect("192.168.1.8", 4433);
  client.write((const uint8_t*)"HELLO\n", 6);
  WiFi.begin("aaa", "bbb");
  int c=0;
  while (1) {
    client.write((const uint8_t*)"HELLO\n", 6);  
    Serial.printf("%d\n", c++);
    delay(1);
  }
  client.stop();
}

void loop() {
  // put your main code here, to run repeatedly:

}

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

No branches or pull requests

5 participants