Skip to content

Conversation

jepler
Copy link

@jepler jepler commented Mar 5, 2024

Incorrect error handling in send/recv would raise an OSError with an incorrect (negative) code.

It's likely that this bug was always happening in the Pico W implementation, which became the basis of the current shared implementation.

Push handling of WANT_{READ,WRITE} down into mbedtls_raise_error and use it in recv_into and send.

Tested by connecting to google.com:443, sending nothing, and trying to read a byte:

import socketpool, ssl, time, wifi
socket = socketpool.SocketPool(wifi.radio)
ctx = ssl.SSLContext()
with ctx.wrap_socket(socket.socket()) as ss:
    ss.connect(("google.com", 443))
    ss.settimeout(1)
    b = bytearray(1)
    try:
        t0 = time.monotonic()
        ss.recv_into(b)
    except Exception as ee:
        t1 = time.monotonic()
        exc = ee
        print(t1-t0)
        raise exc

As desired, an exception OSError: [Errno 116] ETIMEDOUT occurred and the time delta value was 1.0 seconds.

(tested on pycamera)

Closes: #8988

Incorrect error handling in send/recv would raise an OSError with
an incorrect (negative) code.

It's likely that this bug was always happening in the Pico W
implementation, which became the basis of the current shared
implementation.

Push handling of WANT_{READ,WRITE} down into mbedtls_raise_error
and use it in recv_into and send.

Tested by connecting to google.com:443, sending nothing, and trying
to read a byte:

```py
import socketpool, ssl, time, wifi
socket = socketpool.SocketPool(wifi.radio)
ctx = ssl.SSLContext()
with ctx.wrap_socket(socket.socket()) as ss:
    ss.connect(("google.com", 443))
    ss.settimeout(1)
    b = bytearray(1)
    try:
        t0 = time.monotonic()
        ss.recv_into(b)
    except Exception as ee:
        t1 = time.monotonic()
        exc = ee
        print(t1-t0)
        raise exc
```

As desired, an exception `OSError: [Errno 116] ETIMEDOUT` occurred
and the time delta value was 1.0 seconds.

(tested on pycamera)

Closes: adafruit#8988
Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dhalbert
Copy link
Collaborator

dhalbert commented Mar 5, 2024

@justmobilize want to test?

@justmobilize
Copy link

@dhalbert - tested on both a Pico W and UM FeatherS3. Works great!

@dhalbert dhalbert merged commit bf423ff into adafruit:main Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Timeout error went from 116: [Errno 116] ETIMEDOUT to -116
3 participants