Skip to content

ports/espressif/common-hal/socketpool: sockets can block (or raise EAGAIN) instead of raising the actual error #8248

@kbsriram

Description

@kbsriram

CircuitPython version

Adafruit CircuitPython 8.2.0-49-g55c82f45d-dirty on 2023-08-01; DFRobot Beetle ESP32-C3 with ESP32-C3FN4

Code/REPL

#### a couple of reproducible examples

import wifi
import socketpool

wifi.radio.connect("mySSID", "myPASS")
pool = socketpool.SocketPool(wifi.radio)
sock = pool.socket(pool.AF_INET, pool.SOCK_STREAM)
sock.bind((str(wifi.radio.ipv4_address), 9876))
sock.listen(10)
sock.close()
# Blocks rather than raising EBADF
sock.accept()
# Note: In non-blocking mode, raises EAGAIN rather
# than EBADF


###################
sock = pool.socket(pool.AF_INET, pool.SOCK_DGRAM)
sock.bind((str(wifi.radio.ipv4_address), 9876))
sock.close()
# Blocks rather than raising EBADF
sock.recvfrom_into(bytearray(10))
# Note: In non-blocking mode, raises EAGAIN rather
# than EBADF

Behavior

Code blocks (or raises EAGAIN in non-blocking mode)

Description

No response

Additional information

It seems like the code in the espressif binding for socketpool (an example) is missing checks in some places for the actual errno set by lwip.

In certain cases it seems partially masked by checks in shared-binding (an example) but would it be best to raise the actual errno based exception directly from the port, so any issues beyond EBADF can be detected appropriately?

/cc @anecdata @superhac

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions