Skip to content

Sockets break after a soft reboot #8115

Open
@m1cha1s

Description

@m1cha1s

CircuitPython version

Adafruit CircuitPython 8.2.0-rc.0 on 2023-06-23; Raspberry Pi Pico W with rp2040

Code/REPL

from wifi import radio
from socketpool import SocketPool
from builtins import bytearray
from time import sleep
from secrets import secrets

radio.connect(secrets['SSID'], secrets['PASSWD'])

while not radio.connected:
    print("Connecting...")
    sleep(1)

print(f"Connected at address: {radio.ipv4_address}")

socket = SocketPool(radio)


def send_file(conn, filename, content_type):
    with open(filename, "r") as f:
        f_content = f.read()
        conn.sendall(b"HTTP/1.1 200\nContent-Type: ")
        conn.sendall(content_type.encode("utf-8"))
        conn.sendall(b"\n\n")
        conn.sendall(f_content)


with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind(("0.0.0.0", 6969))
    s.listen(100)
    print("Listening...")

    paths = {
            "/": ("index.html", "text/html"),
            "/index.html": ("index.html", "text/html"),
            "/index.js": ("index.js", "application/javascript"),
    }

    while True:
        assert radio.connected
        conn, addr = s.accept()
        with conn:
            print(f"Connected by {addr}")
            data = bytearray([0x00]*1024)
            print(conn.recv_into(data))
            path = data.decode("utf-8").split()[1]
            print(path)
            if path in paths:
                send_file(conn, *paths[path])

Behavior

code.py output:
Connected at address: xxx.xxx.xxx.xxx
Listening...

The code hangs here as if no request are made even when they are.

Description

  • Sockets stop working without any error after some soft reboot (this includes auto-reload)
  • After a hard reset it works fine until it breaks again from where only a hard reset can fix the issue.

Additional information

The error doesn't happen on every single soft reboot, only randomly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions