Skip to content

remove improper clearing of callback state for web workflow background callback#10966

Merged
dhalbert merged 3 commits intoadafruit:mainfrom
dhalbert:fix-background-callback
Apr 22, 2026
Merged

remove improper clearing of callback state for web workflow background callback#10966
dhalbert merged 3 commits intoadafruit:mainfrom
dhalbert:fix-background-callback

Conversation

@dhalbert
Copy link
Copy Markdown
Collaborator

@dhalbert dhalbert commented Apr 21, 2026

@grgrant could you test? Thanks. You can use the artifact builds when they finish.

There were two issues here:

  • background_callback_add_core() was not checking the whole list of callbacks to see if the one being added was a duplicate. It was only checking the first one. It was also checking cb->prev for NULL, for reasons that I don't believe made sense.
  • The web workflow background callback was being zero'd out in supervisor/shared/workflow.c before it was added as a background callback. This meant that if it was already on the background callback list, its next and prev fields were being smashed, and that damaged the list structure

These problems only started being visible after #10840, the ESP-IDF v5.5.3 update, for unknown reasons (maybe some subtle FreeRTOS or wifi changes) and got worse with 10.2.0-rc.0, perhaps because of some workflow changes for Zephyr.

@grgrant I tested with a couple of different programs, to make it easier to wait long enough to see what was going on. One waits 15 seconds, and the other waits for a button push.

import time
import microcontroller

for i in range(15, 0, -1):
    print(i)
    time.sleep(1)

microcontroller.reset()
import time
import board
import digitalio
import microcontroller

button = digitalio.DigitalInOut(board.A0)
button.pull = digitalio.Pull.DOWN

for i in range(10000):
    print(i)
    if button.value:
        microcontroller.reset()
    time.sleep(1)

@grgrant
Copy link
Copy Markdown

grgrant commented Apr 21, 2026

Tests might be a little late for me sent DM with more info

@dhalbert dhalbert marked this pull request as draft April 22, 2026 02:24
@dhalbert
Copy link
Copy Markdown
Collaborator Author

dhalbert commented Apr 22, 2026

Making some changes pointed out by an LLM code review, so draft for now.

EDIT: removed some incorrect changes in background_callback.c. The only real problem was the zeroing of .next and .prev in workflow.c. Re-tested on a Metro ESP32-S3.

@dhalbert dhalbert marked this pull request as ready for review April 22, 2026 02:42
@grgrant
Copy link
Copy Markdown

grgrant commented Apr 22, 2026

Four out of four boards I tested that failed under rc0 succeeded under 10966. I only found the earlier artifacts on 31aab5f I wasn't able to find artifacts for the LLM changes you made later as ed14186.

@dhalbert
Copy link
Copy Markdown
Collaborator Author

@grgrant For some reason my second push did not force a rebuild, so there were no artifacts! I pushed a comment-only commit and was able to get all the jobs to re-run. Here are the new artifacts: https://github.com/adafruit/circuitpython/actions/runs/24775236913?pr=10966

@grgrant
Copy link
Copy Markdown

grgrant commented Apr 22, 2026

All four boards I tested passed using the latest artifacts -- no bug seen.

Feather ESP32-S3 N4R2
ESP32-S2 TFT
QtPy N4R2
Unexpected Maker TinyS2

@dhalbert
Copy link
Copy Markdown
Collaborator Author

@grgrant thank you for the quick testing!

@dhalbert dhalbert requested a review from tannewt April 22, 2026 15:13
Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I'll be happy to move to a proper RTOS.

@dhalbert dhalbert changed the title add background callbacks more carefully; remove improper clearing of callback state remove improper clearing of callback state for web workflow background callback Apr 22, 2026
@dhalbert dhalbert merged commit abb3cbb into adafruit:main Apr 22, 2026
657 of 665 checks passed
@dhalbert dhalbert deleted the fix-background-callback branch April 22, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

microcontroller.reset() causes board to hang indefinitely on subsequent restart

3 participants