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 getaddrinfo does not output the same as Python, Where is my List of multiple addresses. #9711

Open
meeki007 opened this issue Oct 12, 2024 · 2 comments
Labels
bug third-party Awaiting action on a third party for a fix or an answer to a request
Milestone

Comments

@meeki007
Copy link

meeki007 commented Oct 12, 2024

CircuitPython version

Adafruit CircuitPython 9.1.3 on 2024-08-30; Seeed Xiao ESP32-C6 4MB Flash 512KB SRAM with ESP32-C6FH4

Code/REPL

socketpool = socketpool.SocketPool(wifi.radio)
addressInfoTupple = socketpool.getaddrinfo("cats.com", 80)
for individual_addressInfo in addressInfoTupple:
        print(f"individual_addressInfo: {individual_addressInfo}")

Behavior

individual_addressInfo: (2, 1, 0, '', ('172.67.39.47', 80))

Description

I can see the host has multiple A records and addresses for the site.

$ host cats.com
cats.com has address 172.67.39.47
cats.com has address 104.22.47.85
cats.com has address 104.22.46.85
.....

In python I get a List of all the ip addresses, A records, from the host.

individual_addressInfo: (2, 1, 0, '', ('172.67.39.47', 80))
individual_addressInfo: (2, 1, 0, '', ('104.22.47.85', 80))
individual_addressInfo: (2, 1, 0, '', ('104.22.46.85', 80))

Additional information

See documentation ---> https://docs.circuitpython.org/en/latest/shared-bindings/socketpool/#socketpool.SocketPool.getaddrinfo
It says I should be getting a List of Tuples.

Why is this important .... to me.

I am migrating my code from micropython to circuitpython and I noticed that my MQTT messages were not going through from the test device. I then found out one of my servers in my High Availability MQTT cluster was down. I was expecting it to just round robin my List of Tuples from getaddrinfo. Whats the point of outputting a List of Tuples if the list only ever contains 1 value ???

@meeki007 meeki007 added the bug label Oct 12, 2024
@meeki007 meeki007 changed the title socketpool getaddrinfo does not output the same as Python/MicroPython, Where is my List of multiple addresses. socketpool getaddrinfo does not output the same as Python, Where is my List of multiple addresses. Oct 12, 2024
@jepler
Copy link
Member

jepler commented Oct 12, 2024

This is a limitation of lwip, the socket library that is used by Espressif devices (and RP2040 wifi devices, when it comes to that). Their source code .../lwip/src/api/netdb.c states:

 * Due to a limitation in dns_gethostbyname, only the first address of a
 * host is returned.
 * Also, service names are not supported (only port numbers)!

CircuitPython's implementation of getaddrinfo is prepared to return multiple addresses when you call socket.getaddrinfo but the underlying library doesn't provide multiple addresses yet.

@jepler jepler added the third-party Awaiting action on a third party for a fix or an answer to a request label Oct 12, 2024
@jepler jepler added this to the Long term milestone Oct 12, 2024
@meeki007
Copy link
Author

meeki007 commented Oct 12, 2024

CircuitPython's implementation of getaddrinfo is prepared to return multiple addresses when you call socket.getaddrinfo but the underlying library doesn't provide multiple addresses yet.

Good to know! I'll keep my for loop that tires connecting the mqtt client to each address so when this is implemented its waiting to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug third-party Awaiting action on a third party for a fix or an answer to a request
Projects
None yet
Development

No branches or pull requests

2 participants