Skip to content

Sockets break after a soft reboot #8115

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

Open
m1cha1s opened this issue Jun 24, 2023 · 0 comments
Open

Sockets break after a soft reboot #8115

m1cha1s opened this issue Jun 24, 2023 · 0 comments
Labels
bug network rp2040 Raspberry Pi RP2040
Milestone

Comments

@m1cha1s
Copy link

m1cha1s commented Jun 24, 2023

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.

@m1cha1s m1cha1s added the bug label Jun 24, 2023
@tannewt tannewt added the rp2040 Raspberry Pi RP2040 label Jun 26, 2023
@tannewt tannewt added this to the Long term milestone Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug network rp2040 Raspberry Pi RP2040
Projects
None yet
Development

No branches or pull requests

2 participants