Skip to content

Hardfault on esp32s3 when trying to release either a asyncio lock or event #6954

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

Closed
oldfartradioman opened this issue Sep 27, 2022 · 3 comments · Fixed by adafruit/Adafruit_CircuitPython_asyncio#30
Labels
async asyncio related bug
Milestone

Comments

@oldfartradioman
Copy link

CircuitPython version

Adafruit CircuitPython 8.0.0-beta.0-30-g14498f793 on 2022-09-04; Adafruit Feather ESP32S3 4MB Flash 2MB PSRAM with ESP32S3

Code/REPL

import  asyncio
from asyncio import Lock

async def task(i, lock):
    while 1:
        await lock.acquire()
        print("Acquired lock in task", i)
        await asyncio.sleep(0.5)
        lock.release()

async def main():
    lock = asyncio.Lock()  # The Lock instance
    for n in range(1, 4):
        asyncio.create_task(task(n, lock))
    await asyncio.sleep(10)

asyncio.run(main())  # Run for 10s

Behavior

%Run -c $EDITOR_CONTENT
Acquired lock in task 1

Connection lost (EOF)

Use Stop/Restart to reconnect.

Description

Have identical issue with Event

Additional information

No response

@dhalbert
Copy link
Collaborator

If you have time, could you try to replicate this on MicroPython? We use their implementation with very few changes.

@dhalbert dhalbert added this to the 8.x.x milestone Sep 30, 2022
@rbedia
Copy link

rbedia commented Oct 3, 2022

I reported a similar issue here: adafruit/Adafruit_CircuitPython_asyncio#29

The root cause appears to be the change from yield to await core.sleep(0) in acquire(). Using yield takes the lock acquiring task out of the task queue and it only gets put back into the task queue by the lock releasing task. Using sleep causes the acquiring task to put itself back into the queue after the sleep finishes and then acquire the lock even though it wasn't yet released because there isn't a check if the lock is available.

@oldfartradioman
Copy link
Author

Everything works fine on Micropython.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async asyncio related bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants