-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
MemoryError
with HTTPS server and SSLSocket.accept()
on ESP32-S2, Pico W (possibly other)
#9003
Comments
Does this work in 8.x? (I don't think it does.) I suspect this is simply due to not enough memory. I wouldn't mark this for 9.0.0 because it is a feature addition. |
This does work with 8.0.0 on Pico W, but Espressif pieces were not in place until very recently. |
possibly related to #8942 ? |
On PicoW with the adafruit_httpserver library, after the Tested an alternate simple-as-possible socket-level HTTPS server (w/o the library)... free memory before the accept call is ~80KB+, and ~50KB+ before the socket So it may be a "purely" memory issue (as opposed to something else masquerading as a memory error)... perhaps some combination of CP 9 increased core usage / new memory model + richer adafruit_httpserver library. "server" code...import time
import gc
import os
import wifi
import socketpool
import ssl
HOST = "" # see below
PORT = 443
BACKLOG = 2
MAXBUF = 256
def resp(body):
r = "HTTP/1.1 200 OK\r\n"
r += "\r\n"
r += body
return r
time.sleep(3) # wait for serial
ssid = os.getenv("WIFI_SSID")
password = os.getenv("WIFI_PASSWORD")
print("Connecting...", end=" ")
wifi.radio.connect(ssid, password)
print(wifi.radio.ipv4_address)
HOST = str(wifi.radio.ipv4_address)
pool = socketpool.SocketPool(wifi.radio)
print("Create TCP Server socket", (HOST, PORT))
s = pool.socket(pool.AF_INET, pool.SOCK_STREAM)
ssl_context = ssl.create_default_context()
ssl_context.load_verify_locations(cadata="")
ssl_context.load_cert_chain("cert.pem", "key.pem")
ss = ssl_context.wrap_socket(s, server_side=True)
ss.bind((HOST, PORT))
ss.listen(BACKLOG)
print("Listening\n")
buf = bytearray(MAXBUF)
while True:
print(f"Accepting connections (mem={gc.mem_free()})")
conn, addr = ss.accept()
print("Accepted from", addr)
conn.settimeout(None)
size = conn.recv_into(buf, MAXBUF)
print("Received", buf[:size], size, "bytes")
conn.send(resp("nano-https-server").encode())
print(f"Sent response (mem={gc.mem_free()})\n")
conn.close() |
@michalpokusa Could you retry with the latest ConnectionManager library? Thanks. adafruit/Adafruit_CircuitPython_ConnectionManager#16 has fixed several other issues that seem similar. |
@dhalbert My example code does not use ConnectionManager, The issue raises MemoryError on |
@michalpokusa Thanks. Currently when you call In CPython, The amount of SRAM actually available on the ESP32-S2 vs S3 is confusing. The datasheets say the S2 has 320kB and the S3 has 512kB. But in the S3 case, it appears the usable RAM might also be 320kB, because part of the RAM is used for memory caches from the flash, etc. I'm still puzzling this out. |
@dhalbert Would it be possible to create a ssl context without loading the root certs? I understand it is necessary when we want to request website on public internet, but when creating a local server maybe it might be reasonable to use it with self-signed certs? I may also be completely wrong about how this works, in that case please correct me. |
Exactly, that's what might help here, if |
@dhalbert I created my certs using:
There is also a |
CircuitPython version
Code/REPL
Behavior
This example code should be used with
adafruit_httpserver
from PR adafruit/Adafruit_CircuitPython_HTTPServer#88.When using the HTTP server with SSLSocket the
accept()
method throwsMemoryError
without additional details.The example code works correctly on ESP32-S3 (tested on MatrixPortal S3).
Description
Related to:
Additional information
No response
The text was updated successfully, but these errors were encountered: