Silent Failure #20: The Stop Button Cancelled a Handle That Was Already None
The last line in my soak log was reconcile after stop: [['a.py']] . The service had been stopped two seconds earlier. The watcher was supposed to be gone, the debounce was supposed to be cancelled, and the reconciler was still walking the tree and printing the file it had picked up. The test I wrote for that exact path was green. That is the part that still stings. I have been fixing lifecycle…
The story describes a bug discovered in the magitech-ai/anima 2.0 service, which watches files and reloads fibers. The bug occurred when a shutdown request was issued, causing the service to stop prematurely and wake up later with a stashed change, leading to a failed reconciliation. The issue arose because the service cancelled a handle that had been set to None since the watch was installed, causing the flush to wake up unexpectedly and call reconcile() unexpectedly.
The bug was caught by a test that printed the input list of every reconcile, revealing a file in the list after stop. The fix was to give the flush task its own slot, self._fs_flush_task, and cancel it through _cancel_fs_flush() in both the stop() and the side-effect disposer. The change was straightforward but still a mistake, as the correct pattern was three lines above the code being edited.
The fix included adding a test that captured the disposer actually held by the service, called it, and asserted the live task was cancelled. The author also warns against testing the canceller with a task made up in the test, suggesting instead to register the watch, capture the disposer, call it, and assert the live task is cancelled.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to