Skip to content
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

A bug when connecting to not-available endpoints #3056

Closed
gilmaimon opened this issue Aug 1, 2019 · 5 comments
Closed

A bug when connecting to not-available endpoints #3056

gilmaimon opened this issue Aug 1, 2019 · 5 comments

Comments

@gilmaimon
Copy link

My hardware:
Node-MCU ESP32 was used, but I was able to reproduce with any esp32 module I had around me.

I am trying to connect to an endpoint which I know does not exist, however the method WiFiClient.connect returns true (should be false). Then, any calls for send will crash the esp32.

The code I'm using to reproduce is exactly the same as the sketch WiFiClientBasic:

/*
 *  This sketch sends a message to a TCP server
 *
 */

#include <WiFi.h>
#include <WiFiMulti.h>

WiFiMulti WiFiMulti;

void setup()
{
    Serial.begin(115200);
    delay(10);

    // We start by connecting to a WiFi network
    WiFiMulti.addAP("apname", "pass");

    Serial.println();
    Serial.println();
    Serial.print("Waiting for WiFi... ");

    while(WiFiMulti.run() != WL_CONNECTED) {
        Serial.print(".");
        delay(500);
    }

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

    delay(500);
}


void loop()
{
    const uint16_t port = 80;
    const char * host = "192.168.1.1"; // ip or dns

    Serial.print("Connecting to ");
    Serial.println(host);

    // Use WiFiClient class to create TCP connections
    WiFiClient client;

    if (!client.connect(host, port)) {
        Serial.println("Connection failed.");
        Serial.println("Waiting 5 seconds before retrying...");
        delay(5000);
        return;
    }

    // This will send a request to the server
    client.print("Send this data to the server");

    //read back one line from the server
    String line = client.readStringUntil('\r');
    client.println(line);

    Serial.println("Closing connection.");
    client.stop();

    Serial.println("Waiting 5 seconds before restarting...");
    delay(5000);
}

Notice that client.connect(host, port) returns true, even tho the endpoint doesn't exist!

The crash stacktrace (decoded):

PC: 0x400d1b14: WiFiClientRxBuffer::read(unsigned char*, unsigned int) at C:\Users\<username>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\libraries\WiFi\src\WiFiClient.cpp line 107
EXCVADDR: 0x00000008

Decoding stack results
0x400d1b14: WiFiClientRxBuffer::read(unsigned char*, unsigned int) at C:\Users\<username>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\libraries\WiFi\src\WiFiClient.cpp line 107
0x400d1be5: WiFiClient::read(unsigned char*, unsigned int) at C:\Users\<username>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\libraries\WiFi\src\WiFiClient.cpp line 407
0x4013db16: WiFiClient::read() at C:\Users\<username>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\libraries\WiFi\src\WiFiClient.cpp line 318
0x400d3251: Stream::timedRead() at C:\Users\<username>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\cores\esp32\Stream.cpp line 36
0x400d3285: Stream::readStringUntil(char) at C:\Users\<username>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\cores\esp32\Stream.cpp line 287
0x400d187f: loop() at C:\Users\<username>\AppData\Local\Temp\arduino_modified_sketch_306897/WiFiClientBasic.ino line 59
0x400d3d15: loopTask(void*) at C:\Users\<username>\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2\cores\esp32\main.cpp line 19
0x4008877d: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 143
@boarchuz
Copy link
Contributor

boarchuz commented Aug 2, 2019

A fix was merged recently that should address this. Can you update and check if it's still happening?

@gilmaimon
Copy link
Author

I've tested with the latest release I could find on the Boards Manager - 1.0.3-rc1 and the issue still occurs

Thanks for the quick response,
Gil.

@a-c-sreedhar-reddy
Copy link
Contributor

a-c-sreedhar-reddy commented Aug 2, 2019

Dont test with the latest release , test with master.

@boarchuz
Copy link
Contributor

boarchuz commented Aug 2, 2019

Yeah I just tested with latest master and confirmed it is fixed now (and reproduced the error on 1.0.3-rc1).
You'll have to wait for the next release for it to be available in Boards Manager.

@gilmaimon
Copy link
Author

Ok, didn't know that.

Thanks guys, I'm waiting for the next stable release.

Gil.

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

No branches or pull requests

3 participants