Files
Libation/Source/FileManager
Cursor Agentandrmcrackan d27445a128 Stop a disposing file watcher from crashing the process
A Windows CI leg failed with every test passing. FileLiberator.Tests
exited 0xE0434352:

  Unhandled exception. System.InvalidOperationException: The collection has
  been marked as complete with regards to additions.
     at BlockingCollection`1.Add(T item)
     at FileManager.BackgroundFileSystem.FileSystemWatcher_Changed(...)
     at FileSystemWatcher.ReadDirectoryChangesCallback(...)

Stop() disposes the watcher and then completes the collection, on the
assumption that disposing stops events. It does not stop the ones the OS
has already buffered, and on Windows those arrive on a native completion
callback, where an exception is not a failed call - it is a dead process.
So a Libation run that reinitialises or shuts down its file cache while
the Books directory is busy can take the app with it, which is the same
race the tests hit.

Adding to a completed collection is now caught and the event dropped.
That is the right answer rather than a swallow: whoever called Stop() is
either reinitialising, which rebuilds the cache from disk, or disposing.
Stop() also detaches its handlers before disposing and clears the fields,
which narrows the window and makes a second Stop() harmless - the
collection field is cleared only after CompleteAdding, since the
background scanner is waiting on that.

First tests for the class, since it had none: dispose under a flood of
events, dispose twice, and find a file created before and after
construction. They cannot prove this fix - the crash does not reproduce on
Linux even with the original code, because inotify does not deliver
post-dispose events the way Windows does. Windows CI is the only place
that can, so the guard is aimed there.

Co-authored-by: rmcrackan <rmcrackan@gmail.com>
2026-08-17 13:33:52 +00:00
..
2026-02-05 12:48:44 -07:00
2026-02-05 12:48:44 -07:00
2026-02-05 12:48:44 -07:00
2026-05-10 00:37:02 +02:00