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

ESP32-S2 "Out of sockets" in 6.2.0-beta.0 #4057

Closed
anecdata opened this issue Jan 24, 2021 · 7 comments · Fixed by #4049
Closed

ESP32-S2 "Out of sockets" in 6.2.0-beta.0 #4057

anecdata opened this issue Jan 24, 2021 · 7 comments · Fixed by #4049
Assignees
Labels
bug espressif applies to multiple Espressif chips network

Comments

@anecdata
Copy link
Member

anecdata commented Jan 24, 2021

Context manager exit seems to be in place for socket, but:

import time
import wifi
import socketpool

from secrets import secrets

pool = socketpool.SocketPool(wifi.radio)

print("Connect...")
wifi.radio.connect(secrets["ssid"], secrets["password"])
print("RSSI", wifi.radio.ap_info.rssi)

count = 0
packet = bytearray(1)
while True:
    count += 1
    print(count, end=" ")
    packet[0] = 0xFF
    with pool.socket(pool.AF_INET, pool.SOCK_DGRAM) as sock:
        print("Send...")
        sock.sendto(packet, ("192.168.4.32", 16384))
    time.sleep(1)

results in:

Adafruit CircuitPython 6.2.0-beta.0 on 2021-01-22; FeatherS2 with ESP32S2
>>> import ntp
Connect...
RSSI -43
1 Send...
2 Send...
3 Send...
4 Send...
5 Send...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ntp.py", line 21, in <module>
  File "ntp.py", line 21, in <module>
RuntimeError: Out of sockets

CPython version continues past where my patience wears out:

import time
import socket

pool = socket

count = 0
packet = bytearray(1)
while True:
    count += 1
    print(count, end=" ")
    packet[0] = 0xFF
    with pool.socket(pool.AF_INET, pool.SOCK_DGRAM) as sock:
        print("Send...")
        sock.sendto(packet, ("192.168.4.32", 16384))
    time.sleep(1)

6.1.0-rc.1 seems to behave fine.

May be related to adafruit/Adafruit_CircuitPython_Requests#63

@hierophect
Copy link
Collaborator

Probably unrelated to the other issue, other than the general problem of "Hierophect is bad at sockets", ha ha. There's supposed to be a subsystem that tracks what sockets have been initialized and makes sure they shut down on reset or close, but that doesn't seem to be working here. I'll give it another spin with your code and see if I can pin it down.

@tannewt tannewt added bug espressif applies to multiple Espressif chips network labels Jan 25, 2021
@tannewt
Copy link
Member

tannewt commented Jan 25, 2021

@hierophect I don't think it's your problem. I probably never made exit call close. (It should automatically.)

@hierophect
Copy link
Collaborator

@tannewt no, it's my bad, I forgot to make Close de-register handles from the tracking array, only reset_sockets was doing it. I can fold the change into the SSLSocket PR.

@KTibow
Copy link

KTibow commented Feb 15, 2021

I'm still getting this issue with magtag.network.fetch on 6.2.0-beta.2.

@anecdata
Copy link
Member Author

anecdata commented Feb 15, 2021

@KTibow What version of adafruit_requests do you have? There were a couple of socket leaks plugged recently. Can you try the latest if you're not already using it?

@jfabernathy
Copy link

I posted a question in the forum and they directed me here:
I just updated my UF2 file to 6.2.0 Beta 2 and tried the Internet Test from the Learn Guide
https://learn.adafruit.com/adafruit-metro-esp32-s2/circuitpython-internet-test
I get the out of sockets error running the Internet test:
Fetching and parsing json from https://api.github.com/repos/adafruit/circuitpython Traceback (most recent call last): File "code.py", line 55, in <module> File "adafruit_requests.py", line 598, in get File "adafruit_requests.py", line 559, in request File "adafruit_requests.py", line 436, in _get_socket File "adafruit_requests.py", line 433, in _get_socket RuntimeError: Out of sockets
The Error occurs on the second time the code runs. BTW I also updated the Libraries today as well.
code.txt

@jfabernathy
Copy link

Never mind. I got pointed the the latest version that has not been release yet, but is in the pipeline. It worked._

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug espressif applies to multiple Espressif chips network
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants