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

socket hang after REPL disconnection #9150

Open
kevin-tritz opened this issue Apr 6, 2024 · 0 comments
Open

socket hang after REPL disconnection #9150

kevin-tritz opened this issue Apr 6, 2024 · 0 comments
Labels
bug network rp2 Raspberry Pi RP2 Micros
Milestone

Comments

@kevin-tritz
Copy link

CircuitPython version

Adafruit CircuitPython 9.0.0-rc.0 on 2024-03-08; W5500-EVB-Pico with rp2040

Code/REPL

import asyncio
import collections
import supervisor
import mqtt
import ntp as my_ntp
from sensor import Sensor

supervisor.runtime.autoreload = False


class Stop:
    def __init__(self):
        self.value = False


async def proc_cmds(cmd_queue, stop):
    while not stop.value:
        while len(cmd_queue):
            cmd = cmd_queue.popleft()
            if cmd in ['stop', 'STOP']:
                stop.value = True
                continue
        await asyncio.sleep(0.01)


async def sensor_data(sensor, data_queue, ntp, stop):
    while not stop.value:
        data_queue.append(f"{sensor.name}:{sensor.get_data()}:{ntp.timestamp()}")
        await asyncio.sleep(0.01)


async def main():
    stop = Stop()

    sensors = []
    sensors.append(Sensor("sensor1"))
    sensors.append(Sensor("sensor2"))
    sensors.append(Sensor("sensor3"))
    data_queue = collections.deque((), 100)
    cmd_queue = collections.deque((), 10)

    client, pool = mqtt.init()
    client.data_queue = data_queue
    client.cmd_queue = cmd_queue
    ntp = my_ntp.init(pool)

    mqtt_tasks = mqtt.create_tasks(client, stop)
    time_task = asyncio.create_task(my_ntp.update(ntp, stop))
    data_tasks = [asyncio.create_task(sensor_data(
        sensor, data_queue, ntp, stop)) for sensor in sensors]
    cmd_task = asyncio.create_task(proc_cmds(cmd_queue, stop))
    await asyncio.gather(time_task, cmd_task, *mqtt_tasks, *data_tasks)

    mqtt.deinit(client)

asyncio.run(main())

Behavior

I have a W550-EVB-PICO publishing a MQTT message to an rasppi5 broker once every second. It plugs away happily for hours/days at a time. However, if I ssh to the rasppi5, open minicom so I can see the pub messages that are printed to the REPL, and then close minicom or just terminate the ssh session, the PICO stops publishing after a few seconds. If I open up minicom again shortly after, it will resume MQTT publishing. If I wait a bit longer (~minute-ish) it won't resume publishing, and if I interrupt with a Ctrl-C, it shows it stuck here: File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 532, in socket_available. Is there something about connecting/disconnecting from the serial that interferes with socket operations?

Description

No response

Additional information

No response

@kevin-tritz kevin-tritz added the bug label Apr 6, 2024
@tannewt tannewt added rp2 Raspberry Pi RP2 Micros network labels Apr 8, 2024
@tannewt tannewt added this to the Long term milestone Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug network rp2 Raspberry Pi RP2 Micros
Projects
None yet
Development

No branches or pull requests

2 participants