Skip to content

subsequent GET failure - connection missed #5375

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
3 of 6 tasks
Pedroalbuquerque opened this issue Nov 25, 2018 · 2 comments
Closed
3 of 6 tasks

subsequent GET failure - connection missed #5375

Pedroalbuquerque opened this issue Nov 25, 2018 · 2 comments

Comments

@Pedroalbuquerque
Copy link

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: [ESP-12]
  • Core Version: [latest git hash or date]
  • Development Env: [Platformio]
  • Operating System: [MacOS]

Settings in IDE

  • Module: [Nodemcu]
  • 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: [SERIAL]
  • Upload Speed: [115200] (serial upload only)

Problem Description

if 2 GET request are send in a loop and on is pointing to a existing url, both fail

Sketch

[ **** SERVER side code ******] working fine when called from a browser

  server.on("/", handleRoot);

  server.on("/inline", [](){
    server.send(200, "text/plain", "this works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();
[ ***** CLIENTE side code *****]

void loop(){
if(WiFi.status() != WL_CONNECTED){
  WiFi.begin(ssid, password);
  delay(500);
  Serial.println("no WiFi connection");
}else{
  //HTTPClient http;
        Serial.print("[HTTP] begin...\n");
        // configure traged server and url
        http.begin(host, 80, "/inline"); //HTTp
        int httpCode1 = http.GET();
        rptaSrv(httpCode1);
        delay(2000);
        http.begin(host, 80, "/led"); //HTTP
        int httpCode2 = http.GET();
        rptaSrv(httpCode2);
        delay(1000);
    }
}

note that /led does not exist in the server

Debug Messages

[HTTP-Client][begin] host: 192.168.1.79 port: 80 uri: /led
[HTTP-Client] connected to 192.168.1.79:80
[HTTP-Client] sending request header
-----
GET /led HTTP/1.1
Host: 192.168.1.79
User-Agent: ESP8266HTTPClient
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0

-----
[HTTP-Client][handleHeaderResponse] RX: 'HTTP/1.1 404 Not Found'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Type: text/plain'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Length: 51'
[HTTP-Client][handleHeaderResponse] RX: 'Connection: close'

[HTTP-Client][handleHeaderResponse] RX: ''
[HTTP-Client][handleHeaderResponse] code: 404
[HTTP-Client][handleHeaderResponse] size: 51
[HTTP] GET... failed, no connection or no HTTP server
[HTTP] begin...
[HTTP-Client][begin] host: 192.168.1.79 port: 80 uri: /inline
[HTTP-Client] connect. already connected, try reuse!
[HTTP-Client] sending request header
-----
GET /inline HTTP/1.1
Host: 192.168.1.79
User-Agent: ESP8266HTTPClient
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0

-----
[HTTP-Client][returnError] error(-5): connection lost
[HTTP] GET... failed, no connection or no HTTP server
[HTTP-Client][begin] host: 192.168.1.79 port: 80 uri: /led
[HTTP-Client] connected to 192.168.1.79:80
[HTTP-Client] sending request header
-----
GET /led HTTP/1.1
Host: 192.168.1.79
User-Agent: ESP8266HTTPClient
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0

-----
[HTTP-Client][handleHeaderResponse] RX: 'HTTP/1.1 404 Not Found'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Type: text/plain'

[HTTP-Client][handleHeaderResponse] RX: 'Content-Length: 51'
[HTTP-Client][handleHeaderResponse] RX: 'Connection: close'
[HTTP-Client][handleHeaderResponse] RX: ''
[HTTP-Client][handleHeaderResponse] code: 404
[HTTP-Client][handleHeaderResponse] size: 51
[HTTP] GET... failed, no connection or no HTTP server
[HTTP] begin...
[HTTP-Client][begin] host: 192.168.1.79 port: 80 uri: /inline
[HTTP-Client] connect. already connected, try reuse!
[HTTP-Client] sending request header
-----
GET /inline HTTP/1.1
Host: 192.168.1.79
User-Agent: ESP8266HTTPClient
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0

-----


note the "[HTTP-Client][returnError] error(-5): connection lost "

If I change the HTTPClient::connect() to

bool HTTPClient::connect(void)
{

    if(connected()) {
        end();
    }
 ...

everything starts to work fine.

[HTTP] begin...
[HTTP-Client][begin] host: 192.168.1.79 port: 80 uri: /inline
[HTTP-Client] connected to 192.168.1.79:80
[HTTP-Client] sending request header
-----
GET /inline HTTP/1.1
Host: 192.168.1.79
User-Agent: ESP8266HTTPClient
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0

-----
[HTTP-Client][handleHeaderResponse] RX: 'HTTP/1.1 200 OK'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Type: text/plain'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Length: 18'

[HTTP-Client][handleHeaderResponse] RX: 'Connection: close'
[HTTP-Client][handleHeaderResponse] RX: ''
[HTTP-Client][handleHeaderResponse] code: 200
[HTTP-Client][handleHeaderResponse] size: 18
[HTTP-Client][writeToStreamDataBlock] connection closed or file end (written: 18).
[HTTP-Client][end] tcp stop
this works as well
[HTTP-Client][begin] host: 192.168.1.79 port: 80 uri: /led
[HTTP-Client] connected to 192.168.1.79:80
[HTTP-Client] sending request header
-----
GET /led HTTP/1.1
Host: 192.168.1.79
User-Agent: ESP8266HTTPClient
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0

-----
[HTTP-Client][handleHeaderResponse] RX: 'HTTP/1.1 404 Not Found'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Type: text/plain'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Length: 51'
[HTTP-Client][handleHeaderResponse] RX: 'Connection: close'
[HTTP-Client][handleHeaderResponse] RX: ''
[HTTP-Client][handleHeaderResponse] code: 404
[HTTP-Client][handleHeaderResponse] size: 51

[HTTP] GET... failed, no connection or no HTTP server
[HTTP] begin...
[HTTP-Client][begin] host: 192.168.1.79 port: 80 uri: /inline
[HTTP-Client][end] still data in buffer (51), clean up.
[HTTP-Client][end] tcp stop
[HTTP-Client] connected to 192.168.1.79:80
[HTTP-Client] sending request header
-----
GET /inline HTTP/1.1
Host: 192.168.1.79
User-Agent: ESP8266HTTPClient
Connection: close
Accept-Encoding: identity;q=1,chunked;q=0.1,*;q=0

-----
[HTTP-Client][handleHeaderResponse] RX: 'HTTP/1.1 200 OK'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Type: text/plain'
[HTTP-Client][handleHeaderResponse] RX: 'Content-Length: 18'
[HTTP-Client][handleHeaderResponse] RX: 'Connection: close'
[HTTP-Client][handleHeaderResponse] RX: ''
[HTTP-Client][handleHeaderResponse] code: 200
[HTTP-Client][handleHeaderResponse] size: 18
[HTTP-Client][writeToStreamDataBlock] connection closed or file end (written: 18).
[HTTP-Client][end] tcp stop
this works as well



@devyte
Copy link
Collaborator

devyte commented Nov 27, 2018

Note: sounds like something wrong with reuse.

@earlephilhower
Copy link
Collaborator

Dupe of #6149 . Let's track there.

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