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

socketpool.Socket is missing getaddrinfo #4394

Open
johncblacker opened this issue Mar 13, 2021 · 6 comments
Open

socketpool.Socket is missing getaddrinfo #4394

johncblacker opened this issue Mar 13, 2021 · 6 comments
Labels
cpython api modules from cpython enhancement espressif applies to multiple Espressif chips network
Milestone

Comments

@johncblacker
Copy link

Documentation includes:
socket.getaddrinfo(host: str, port: int) → Tuple[int, int, int, str, str]
Gets the address information for a hostname and port

Returns the appropriate family, socket type, socket protocol and address information to call socket.socket() and socket.connect() with, as a tuple.
But it has not been implemented on the esp32-s2 port. Just wanted to insert this as a reminder.

@tannewt tannewt added cpython api modules from cpython espressif applies to multiple Espressif chips network labels Mar 13, 2021
@tannewt tannewt added this to the Long term milestone Mar 13, 2021
@anecdata
Copy link
Member

anecdata commented Mar 13, 2021

See RTD:

>>> import wifi
>>> import socketpool
>>> from secrets import secrets
>>> 
>>> wifi.radio.connect(secrets['ssid'], secrets['password'])
>>> 
>>> pool = socketpool.SocketPool(wifi.radio)
>>> pool.getaddrinfo("adafruit.com", 443)
[(0, 0, 0, '', ('104.20.38.240', 443))]
>>> 

This is old, not used. This is for native (ESP32-S2) Socket.

Apologies if I'm misunderstanding the issue. Family can be AF_INET or AF_INET6, though AF_INET6 is not currently supported (will raise exception). Type can be STREAM, DGRAM, or RAW. STREAM and DGRAM should be fine, I'm unsure about support status for RAW. Proto is currently inferred from Family, and can be IP or IPV6, though again IPV6 is currently unsupported (will raise exception).

Addendum: I think I see the issue. Although getaddrinfo returns IP and port accurately, looks like Family, Type, and Proto are currently hard-coded and will always be returned as 0,0,0 (AF_INET, STREAM, IP). e.g.,

>>> pool.getaddrinfo("pool.ntp.org", 123)
[(0, 0, 0, '', ('13.86.101.172', 123))]
>>> pool.getaddrinfo("pool.ntp.org", 123, type=pool.SOCK_DGRAM)
[(0, 0, 0, '', ('13.86.101.172', 123))]

@PaulskPt
Copy link

PaulskPt commented Feb 8, 2022

My MAGTAG date and time app was running OK for months. Recently the script started crashing.
In this moment I am getting OSError -2 on a MAGTAG.
The MAGTAG is flashed with:
Adafruit CircuitPython 7.1.1 on 2022-01-14; Adafruit MagTag with ESP32S2
Board ID:adafruit_magtag_2.9_grayscale

Script crashes here with OSError -2:

In file adafruit_requests.py, line 536
addr_info = self._socket_pool.getaddrinfo( host, port, 0, self._socket_pool.SOCK_STREAM )[0]

whereas:
self._socket_pool = <SocketPool>

where also:
ping google.com (8.8.8.8) timed-out
ping google.com (8.8.4.4) timed-out
ping router in LAN 9.0 mSec
WiFi connected to LAN access-point
IP address received: 192.168.1.101

proto = 'https:'
host = 'io.adafruit.com'
port = 443
timeout = 60
addr_info = 0

This is the boot info the ESP32s2 is sending via TX:

2022-02-08_11h25_MAGTAG_boot_output_to_RX_TX

@tannewt
Copy link
Member

tannewt commented Feb 8, 2022

@PaulskPt please open a new issue. I'm not sure your issue is related to this one.

@PaulskPt
Copy link

PaulskPt commented Feb 8, 2022

OK

@PaulskPt
Copy link

PaulskPt commented Feb 8, 2022

@tannewt You know what? I took out the calls to wifi.radio.ping() because all ping efforts into WAN resulted in a timed-out error. Only the ping to the router in the LAN was positive. Because I read in a discussion of issue #3836 that a timed-out ping caused the socket to be closed, I commented-out the block of ping commands. Then the script ran as expected ! Problem solved!

Just for the record the latest results:

Some defines and print statements I added for debugging purposes:
socket = <SSLSocket>
request() params: host: io.adafruit.com, port: 443, proto: 'https:', timeout: 60
Session._get_socket(): self._socket_pool = <SocketPool>
spss = self._socket_pool.SOCK_STREAM
ai = self._socket_pool.getaddrinfo(host, port, 0, spss)
addr_info = ai[0]

host = io.adafruit.com
port = 443
spss = 0
addr_info = [(0, 0, 0, '', ('52.54.163.195', 443))]

result : <Response object at 0x3fd8e8f0>
2022-02-08 19:46:10.179 039 2 +0000 WET

@PaulskPt
Copy link

PaulskPt commented Feb 9, 2022

@tannewt The script ran already uninterrupted from yesterday 19:46 local until this moment in the next morning.

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

No branches or pull requests

4 participants