meshtastic / firmware

Meshtastic device firmware
https://meshtastic.org
GNU General Public License v3.0
3.59k stars 894 forks source link

[Bug]: Web client initial load is very slow (90 seconds) in Chrome (compared to Firefox - 4 seconds) #5385

Open cpatulea opened 2 hours ago

cpatulea commented 2 hours ago

Category

WiFi

Hardware

Heltec V3

Firmware Version

2.5.11.8e2a3e5

Description

Chrome (~90 seconds):

https://github.com/user-attachments/assets/6945fdc0-bc10-4005-93c8-74faf714507e

Firefox (~4 seconds):

https://github.com/user-attachments/assets/60737f5f-e9b8-48ba-b4e9-88adb8af74ee

I think this is because Chrome re-establishes the connection (TCP+TLS) for each request:

Screenshot 2024-11-17 at 3 17 12 PM Screenshot 2024-11-17 at 3 18 42 PM

Connection keep-alive is supposed to work, and make a huge difference, as seen in Firefox, where each request takes only ~60 ms.

I thought I figured out the reason Chrome connections don't keep alive but I found some conflicting clues so now I'm not so sure I understand why.

Relevant log output

No response

cpatulea commented 2 hours ago

It does seem like it's Chrome which decides to close the connection:

Screenshot 2024-11-17 at 3 31 12 PM
cpatulea commented 1 hour ago

Hmm, might be the preflight OPTIONS requests, which the ESP32 responds with 404 and 'Connection: close':

Screenshot 2024-11-17 at 3 36 28 PM

OPTIONS /api/v1/fromradio?all=false HTTP/1.1 Accept-Encoding: gzip, deflate, br, zstd Accept-Language: en-US,en;q=0.9 Access-Control-Request-Method: GET Access-Control-Request-Private-Network: true Connection: keep-alive Host: 192.168.0.190 Origin: https://client.meshtastic.org Referer: https://client.meshtastic.org/ Sec-Fetch-Dest: empty Sec-Fetch-Mode: cors Sec-Fetch-Site: cross-site User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

HTTP/1.1 404 Not Found Connection: close Content-Type: text/plain;charset=utf8

cpatulea commented 1 hour ago

Code link for 404 showing explicit 'Connection: close': https://github.com/meshtastic/esp32_https_server/blob/896f1771ceb5979987a0b41028bf1b4e7aad419b/src/HTTPConnection.cpp#L277

cpatulea commented 1 hour ago

Recent CORS policy issue, not sure if related: https://github.com/meshtastic/web/issues/249

cpatulea commented 1 hour ago

/api/v1/fromradio doesn't seem to have a OPTIONS handler?

https://github.com/meshtastic/firmware/blob/89469fcb88240617146dc11bc3cad01dcbf3f3a6/src/mesh/http/ContentHandler.cpp#L77C58-L77C75

cpatulea commented 1 hour ago

Serial log during this:

[HTTPS:I] Request: OPTIONS /api/v1/fromradio?all=false (FID=53)
[HTTPS:W] Could not find a matching resource
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:E] SSL_accept failed. Aborting handshake. FID=53
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:I] Request: GET /api/v1/fromradio?all=false (FID=53)
DEBUG | ??:??:?? 35 [WebServer] webAPI handleAPIv1FromRadio
DEBUG | ??:??:?? 35 [WebServer] FromRadio=STATE_SEND_MY_INFO
DEBUG | ??:??:?? 35 [WebServer] webAPI handleAPIv1FromRadio, len 25
[HTTPS:I] Request: OPTIONS /api/v1/fromradio?all=false (FID=53)
[HTTPS:W] Could not find a matching resource
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:E] SSL_accept failed. Aborting handshake. FID=53
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:I] Request: GET /api/v1/fromradio?all=false (FID=53)
DEBUG | ??:??:?? 37 [WebServer] webAPI handleAPIv1FromRadio
DEBUG | ??:??:?? 37 [WebServer] Send My NodeInfo
DEBUG | ??:??:?? 37 [WebServer] webAPI handleAPIv1FromRadio, len 92
[HTTPS:I] Request: OPTIONS /api/v1/fromradio?all=false (FID=53)
[HTTPS:W] Could not find a matching resource
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:E] SSL_accept failed. Aborting handshake. FID=53
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:I] Request: GET /api/v1/fromradio?all=false (FID=53)
DEBUG | ??:??:?? 38 [WebServer] webAPI handleAPIv1FromRadio
DEBUG | ??:??:?? 38 [WebServer] Send device metadata
DEBUG | ??:??:?? 38 [WebServer] webAPI handleAPIv1FromRadio, len 37
[HTTPS:I] Request: OPTIONS /api/v1/fromradio?all=false (FID=53)
[HTTPS:W] Could not find a matching resource
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:E] SSL_accept failed. Aborting handshake. FID=53
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:I] Request: GET /api/v1/fromradio?all=false (FID=53)
DEBUG | ??:??:?? 40 [WebServer] webAPI handleAPIv1FromRadio
DEBUG | ??:??:?? 40 [WebServer] webAPI handleAPIv1FromRadio, len 13
[HTTPS:I] Request: OPTIONS /api/v1/fromradio?all=false (FID=53)
[HTTPS:W] Could not find a matching resource
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:E] SSL_accept failed. Aborting handshake. FID=53
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:I] Request: GET /api/v1/fromradio?all=false (FID=53)
DEBUG | ??:??:?? 42 [WebServer] webAPI handleAPIv1FromRadio
DEBUG | ??:??:?? 42 [WebServer] webAPI handleAPIv1FromRadio, len 6
[HTTPS:I] Request: OPTIONS /api/v1/fromradio?all=false (FID=53)
[HTTPS:W] Could not find a matching resource
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:E] SSL_accept failed. Aborting handshake. FID=53
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:I] Request: GET /api/v1/fromradio?all=false (FID=53)
DEBUG | ??:??:?? 43 [WebServer] webAPI handleAPIv1FromRadio
DEBUG | ??:??:?? 43 [WebServer] webAPI handleAPIv1FromRadio, len 6
[HTTPS:I] Request: OPTIONS /api/v1/fromradio?all=false (FID=53)
[HTTPS:W] Could not find a matching resource
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:E] SSL_accept failed. Aborting handshake. FID=53
[HTTPS:I] Connection closed. Socket FID=53
[HTTPS:I] New connection. Socket FID=53
[HTTPS:I] Request: GET /api/v1/fromradio?all=false (FID=53)