-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix 3986 background reset remove existing usb callback #4122
Conversation
just a proof to show that issue analysis is correct
unconditionally schedule usb background after background_callback_reset()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very, very much for spending the time on this! If you want to fix anything up, I'll wait for new commits. Otherwise we can merge as is.
It is always my pleasure to help, don't hesitate to tag me for any usb-related bugs. Except for choosing between run the background immediately vs schedule as PR. I have nothing to add. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my testing, this works, and fixes a serious problem. I will merge. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I shrank a couple of overflowing builds. All set now!
fix #3986
Issue
run_code.py decide to reload (AUTO_RELOAD) and run background_callback_reset() while background list is still queued up with usb event.
To sum up the issue is not related to usb stack, it seems to be caused by auto-reload while background task are still queued up.
background_callback_run_all()
is not guarantee to execute all the background since while executing background, those function can potentially trigger more usb ISR.https://github.com/adafruit/circuitpython/blob/main/supervisor/shared/background_callback.c#L91
We can modify background_callback_run_all() to loop over while callback_head is not NULL. However, there is still race condition where the usb (or other) ISR is triggered during
run_code_py: 340: // reload request == true
and thecleanup_after_vm()
. I actually don't understand the background mechanism enough to propose a sound solution here. @dhalbert let me know if my analysis makes sense to you.Originally posted by @hathach in #3986 (comment)
Solution
background_callback_add(&usb_callback, usb_background_do, NULL);
unconditionally somewhere afterbackground_callback_reset()
.Originally posted by @hathach in #3986 (comment)