Closed ipapp closed 5 years ago
Hi @ipapp
Thanks for reporting this issue! Indeed there's a bug in ws_transport, so that ws header is not received properly if fragmented. Correct fix should be very close to your proposed workaround (just checking for http header termination instead of fixed size):
int header_len = 0;
do {
if ((len = esp_transport_read(ws->parent, ws->buffer + header_len, DEFAULT_WS_BUFFER - header_len, timeout_ms)) <= 0) {
ESP_LOGE(TAG, "Error read response for Upgrade header %s", ws->buffer);
return -1;
}
header_len += len;
ws->buffer[header_len] = '\0';
ESP_LOGD(TAG, "Chunk %d", header_len);
} while (NULL == strstr(ws->buffer, "\r\n\r\n"));
Thanks again, will be fixed.
Great, thanks! I'll try it in the coming days. I have one question: in case the response is wrong, will the esp_transport_read
take care of timeout and/or error handling?
@ipapp Yes, esp_transport_read
return <=0
in case of timeout or error, so returns to the caller (mqtt connect, which prints the errno
). Also, this is just a quick fix, the actual one will be merged in coming days.
hello i use B4A it not support WSS for MQTT can help me?
ghaneipour@gmail.com
Environment
Problem Description
I am trying to connect to flespi.io over Secure WebSocket. The WS upgrade process fails, as the first upgrade response is not received in single
esp_transport_read
function call. It is not up to the wrong case of Sec-WebSocket-Accept.Expected Behavior
I would expect to connect to wss://mqtt.flespi.io. It uses port 443. Other clients I made using e.g. node.js works fine when supplied the same credentials and URL.
Actual Behavior
I get the following errors:
And the board cannot connect to wss://flespi.io:xxxx.
Steps to reproduce
Analysis
The issue seems to be in the
ws_connect
function intransport_ws.c
, line 116.The
esp_transport_read
function at first call returns 34 bytes, which is not the whole response. Empirically I figured out that the response is 159 bytes. If I add a code like this, it works.It results in 3 calls, returning 34, 123 and 2 bytes (159 in total). This is not a solution, as 159 byte response is likely just a special case for flespi.io! My feeling is that:
esp_transport_read
exists prematurely,ws_connect
has to handle the fragmented response.Code to reproduce this issue
Debug Logs
My extended log on error, when
esp_transport_read
is called only once inws_connect
, line 116.