Compare commits

...
Author SHA1 Message Date
nvrl ce97b86638 Merge remote-tracking branch 'origin/main' into docs/bugs-sim-flakes
# Conflicts:
#	crates/pdfs-fuse/src/sim/daemon.rs
2026-11-26 02:42:31 +01:00
nvrl 3879ee7922 Merge pull request #143 from narrrl/refactor/pdfs-sync
Land #137, #138 and #141 on main
2026-11-26 02:37:08 +01:00
nvrl d40c7f7ebb Merge pull request #140 from narrrl/fix/sim-fail-fast
fix(sim): run one simulation's daemons at a time, and abort a mount that will not stop (B297)
2026-11-26 01:38:03 +01:00
nvrl fe9528ce29 Merge branch 'docs/bugs-sim-flakes' into fix/sim-fail-fast 2026-11-26 01:37:51 +01:00
nvrl b6ee07161c Merge pull request #139 from narrrl/docs/architecture-4.0
docs(architecture): the 4.0 target, its rules and its steps
2026-11-26 01:37:21 +01:00
nvrl c2f5537bd7 fix(sim): run one simulation's daemons at a time, and abort a mount that will not stop (B297)
Daemon::start takes a turn: a daemon started on one test thread waits
while another test thread still has one, so plain cargo test no longer
runs the simulations side by side. A stop that does not end within 60 s,
or a daemon alive after 20 minutes, aborts the mount's FUSE connection,
which the mounting user may do, so a mount that stops answering fails the
test instead of hanging the run.
2026-11-26 01:29:54 +01:00
nvrl 06d099f0de docs(architecture): the 4.0 target, its rules and its steps
Where 4.0 takes the daemon: services that own their state and threads,
behind ports, with dependencies pointing inward. Six rules to check in
review, and the steps from the current open fixes to pdfs-vfs.
2026-11-26 01:28:27 +01:00
nvrl c171a713cb Merge pull request #136 from narrrl/docs/bugs-sim-flakes
docs(bugs): B297, the simulations fail and hang when run in parallel
2026-11-26 01:10:37 +01:00
nvrl 23a961d020 Merge branch 'main' into docs/bugs-sim-flakes 2026-11-26 01:10:26 +01:00
nvrl d84b35c039 Merge pull request #135 from narrrl/feat/db-read-no-writer-fallback
fix(core,fuse): fail a read rather than wait on the writer, and keep one diagnostics probe
2026-11-26 01:09:55 +01:00
nvrl bf7d26ce23 docs(bugs): list B295 in the index 2026-11-26 01:04:33 +01:00
nvrl 62ae18efbf docs(bugs): B297 is the simulations run in parallel
The local runs behind the first version left out --test-threads=1, which
CI and TESTING.md use. Run serially, the same branches pass in CI.
2026-11-26 00:34:34 +01:00
nvrl 7cffeb924d docs(bugs): B297, the simulations fail or hang about one run in two
Twelve local runs of the full suite on three branches based on main:
five passed, six failed and one hung. CI on main fails too. Records
which tests fail, with what, and the hang's stuck FUSE request.
2026-11-26 00:34:34 +01:00
3 changed files with 246 additions and 0 deletions

No files matched your search

+141
View File
@@ -30,6 +30,16 @@ const MOUNT_DEADLINE: Duration = Duration::from_secs(20);
/// How long a restart may wait for the last run to let go of its database.
const LAST_RUN_DEADLINE: Duration = Duration::from_secs(30);
/// How long a stop may wait for the mount to end before it aborts the FUSE
/// connection. A mount that stops answering otherwise hangs the test, and the
/// whole run with it (`docs/BUGS.md` B297).
const STOP_DEADLINE: Duration = Duration::from_secs(60);
/// How long one daemon may live. Past this, its FUSE connection is aborted, so
/// a test blocked on a request the mount never answers fails with `ENOTCONN`
/// instead of hanging the run. The whole suite takes about 15 minutes in CI.
const LIFETIME_LIMIT: Duration = Duration::from_secs(20 * 60);
pub(crate) struct Daemon {
pub(crate) client: FakeClient,
pub(crate) mountpoint: PathBuf,
@@ -38,6 +48,13 @@ pub(crate) struct Daemon {
stop: SyncSender<()>,
mount: Option<JoinHandle<io::Result<MountOutcome>>>,
rt: Option<tokio::runtime::Runtime>,
/// The mount's FUSE connection, as `/sys/fs/fuse/connections` names it.
connection: u64,
/// Dropped with the daemon, which ends the thread enforcing
/// [`LIFETIME_LIMIT`].
_alive: std::sync::mpsc::Sender<()>,
/// Dropped after `shut_down`, so the next simulation waits for this one.
_turn: Turn,
}
impl Daemon {
@@ -45,6 +62,7 @@ impl Daemon {
/// A later start on the same `dir` is a restart: it finds the queue, the
/// cache and the database the last run left.
pub(crate) fn start(dir: &Path, client: FakeClient) -> io::Result<Self> {
let turn = Turn::take();
log_to_test_output();
isolate_from_the_developer();
let mountpoint = dir.join("mnt");
@@ -112,6 +130,27 @@ impl Daemon {
}
std::thread::sleep(Duration::from_millis(20));
}
let connection = {
use std::os::unix::fs::MetadataExt;
u64::from(libc::minor(std::fs::metadata(&mountpoint)?.dev()))
};
let (alive, dropped) = std::sync::mpsc::channel::<()>();
{
let mountpoint = mountpoint.clone();
std::thread::Builder::new()
.name("sim-lifetime".into())
.spawn(move || {
if let Err(std::sync::mpsc::RecvTimeoutError::Timeout) =
dropped.recv_timeout(LIFETIME_LIMIT)
{
eprintln!(
"{}: the daemon outlived {LIFETIME_LIMIT:?}; aborting its FUSE connection",
mountpoint.display()
);
abort_connection(connection);
}
})?;
}
Ok(Self {
client,
mountpoint,
@@ -120,6 +159,9 @@ impl Daemon {
stop,
mount: Some(mount),
rt: Some(rt),
connection,
_alive: alive,
_turn: turn,
})
}
@@ -215,6 +257,21 @@ impl Daemon {
return Ok(MountOutcome::Shutdown);
};
let _ = self.stop.try_send(());
if !wait_until(STOP_DEADLINE, || mount.is_finished()) {
abort_connection(self.connection);
let _ = wait_until(STOP_DEADLINE, || mount.is_finished());
if !mount.is_finished() {
// Joining would hang the run; leak the thread instead.
return Err(io::Error::other(format!(
"{}: the mount did not end after its FUSE connection was aborted",
self.mountpoint.display()
)));
}
return Err(io::Error::other(format!(
"{}: the mount did not stop within {STOP_DEADLINE:?}, so its FUSE connection was aborted",
self.mountpoint.display()
)));
}
let outcome = mount
.join()
.unwrap_or_else(|_| Err(io::Error::other("mount thread panicked")));
@@ -231,6 +288,61 @@ impl Drop for Daemon {
}
}
/// Abort FUSE connection `connection`: every request waiting on it fails with
/// `ENOTCONN`, and the mount's session ends. The connection belongs to the
/// user who mounted it, so this needs no privileges.
fn abort_connection(connection: u64) {
let path = format!("/sys/fs/fuse/connections/{connection}/abort");
if let Err(error) = std::fs::write(&path, "1") {
eprintln!("could not abort {path}: {error}");
}
}
/// One simulation's turn to run daemons. The simulations share the process:
/// its environment (see [`isolate_from_the_developer`]), its cores and its
/// mounts. Run side by side, as plain `cargo test` does, they miss their
/// deadlines and can hang (`docs/BUGS.md` B297). So a daemon started on one
/// test thread waits while another test thread still has one.
struct Turn;
/// The test thread whose daemons run now, and how many it has.
static TURN: parking_lot::Mutex<Option<(std::thread::ThreadId, usize)>> =
parking_lot::Mutex::new(None);
static TURN_FREE: parking_lot::Condvar = parking_lot::Condvar::new();
impl Turn {
fn take() -> Self {
let me = std::thread::current().id();
let mut turn = TURN.lock();
loop {
match turn.as_mut() {
None => {
*turn = Some((me, 1));
return Turn;
}
Some((owner, count)) if *owner == me => {
*count += 1;
return Turn;
}
Some(_) => TURN_FREE.wait(&mut turn),
}
}
}
}
impl Drop for Turn {
fn drop(&mut self) {
let mut turn = TURN.lock();
if let Some((_, count)) = turn.as_mut() {
*count -= 1;
if *count == 0 {
*turn = None;
TURN_FREE.notify_all();
}
}
}
}
/// Whether a file system is mounted at `path`: it sits on another device than
/// its parent.
fn is_mounted(path: &Path) -> bool {
@@ -369,6 +481,35 @@ mod tests {
use pdfs_core::control::{RefreshScope, SyncIssue};
use std::collections::BTreeMap;
#[test]
#[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"]
fn a_simulation_on_another_thread_waits_for_this_ones_daemons() {
// Side by side, the simulations missed their deadlines and could hang
// on a mount (B297).
let drive = FakeDrive::new();
let first = Daemon::start(&scratch("turn-first"), drive.client(1, Faults::lan())).unwrap();
let second_up = Arc::new(std::sync::atomic::AtomicBool::new(false));
let other = {
let drive = drive.clone();
let second_up = second_up.clone();
std::thread::spawn(move || {
let second =
Daemon::start(&scratch("turn-second"), drive.client(2, Faults::lan())).unwrap();
second_up.store(true, std::sync::atomic::Ordering::SeqCst);
second.stop().unwrap();
})
};
std::thread::sleep(Duration::from_secs(2));
assert!(!second_up.load(std::sync::atomic::Ordering::SeqCst));
// A second daemon on this thread does not wait for the first.
let restarted = first.restart().unwrap();
assert!(!second_up.load(std::sync::atomic::Ordering::SeqCst));
restarted.stop().unwrap();
other.join().unwrap();
assert!(second_up.load(std::sync::atomic::Ordering::SeqCst));
}
#[test]
#[ignore = "mounts FUSE: run with `cargo test -p pdfs-fuse sim:: -- --ignored`"]
fn diagnostics_count_the_calls_made_to_drive() {
+56
View File
@@ -672,4 +672,60 @@ local state per node as each batch lands.
- **Mirrored folders** still have their own engine (§7). They move onto the local tree and the
queue after that.
### 4.0: from one daemon to composed services
The daemon grew one feature at a time inside `pdfs-fuse`, which now holds the FUSE handlers, the
drain, the sync engine, photos, thumbnails, takeout, devices, the control server, the supervisor
and diagnostics. Everything shares one `Core` struct (`lib.rs`) with over seventy fields, so any
code can take any lock in any order, and a new feature can deadlock an old one (`docs/BUGS.md`
B110, the cold size upgrade, the diagnostics threads stuck behind the database writer). Over
forty threads are spawned ad hoc, each with its own stop and join rules. The only real seam is
`DriveApi` (`drive.rs`), which is what lets the simulation tests run against a fake Drive.
4.0 splits the daemon into services that each own their state and threads, behind ports that can
be swapped and tested alone. Dependencies point inward; inner crates never see GTK, `fuser`,
`libc` error numbers or SDK node types.
```
apps pdfs-cli, pdfs-gui talk to the daemon over the control socket only
daemon pdfs-daemon builds the services, supervisor, diagnostics, control server
adapters pdfs-fuse (Linux FUSE), pdfs-local (watch, scan, place), pdfs-drive (SDK adapter, fake Drive)
services pdfs-sync (mirrors), pdfs-vfs (mounted files: objects, handles, generations), photos, ...
base pdfs-store (SQLite, migrations), pdfs-core (config, protocol, ids, errors)
```
Six rules hold that shape:
1. **Ownership.** Each service owns its state and its threads. Services talk through typed ports
or messages, never through another service's lock.
2. **Lifecycle.** Each service starts from its dependencies and returns a handle with `stop`, a
bounded `join` and a health snapshot. The supervisor starts the services in dependency order
and stops them in reverse. No thread is left detached.
3. **No lock across a boundary.** No lock is held across an SDK call, a FUSE reply or kernel
notification, a blocking send or a join. Debug builds check the order of the nested locks
that remain.
4. **Short transactions.** A read never falls back to the writer connection. Diagnostics use
their own connection and report "busy" instead of waiting.
5. **Absence is a fact, not a gap.** A locked, unreadable, partly listed or ignored path is never
read as deleted, whether in sync, in the mount or behind a locked store.
6. **Headless tests.** Each service runs in tests without a mount, a desktop or a Proton account:
sync against the fake Drive and a temporary directory, the mounted-files service against a
fake store.
The work goes in steps. Each ships the same behaviour with the simulation tests green:
| Step | What |
|---|---|
| 0 | Finish what is open: the resumable walk of Drive's changed folders (B294), the ignored `set_len` error on a resize (B295), a reopen after close that depends on the single dispatch thread, and no conflict copy when a lost reply left the same content on Drive |
| 1 | Seams and measurement: a `DriveApi` decorator that counts calls and their time, diagnostics that cannot hang (B296), lock-order checks, a live one-edit benchmark |
| 2 | Move code into `pdfs-store`, `pdfs-drive` and `pdfs-sync` without changing it |
| 3 | Split `Core` into services with a lifecycle, under a supervisor in `pdfs-daemon` |
| 4 | Sync on evidence: a local dirty set, typed absence, a delete guard over the whole walk, and a durable intent for each effect, first in shadow mode |
| 5 | `pdfs-vfs`: open files, then directories and renames, behind the FUSE adapter |
| 6 | One admission policy for mirrors, reads and writeback |
Steps 0 to 3 are 4.0.0. Steps 4 to 6 follow in 4.x, one service at a time. Out of scope for
now: an encrypted local vault (full-disk encryption covers a copied disk today), Windows and
macOS adapters, and a separate repository for the sync engine.
[ROADMAP.md](ROADMAP.md) tracks these and the rest of the planned work.
+49
View File
@@ -108,6 +108,7 @@ a live account since.
| Entry | Title |
|---|---|
| [B297](#b297--the-simulations-fail-and-hang-when-run-in-parallel-and-nothing-stops-that) | The simulations fail and hang when run in parallel, and nothing stops that |
| [B296](#b296--a-busy-database-stalls-reads-and-piles-up-diagnostics-threads) | A busy database stalls reads, and piles up diagnostics threads |
| [B294](#b294--a-mirror-folder-too-large-to-finish-in-one-run-never-syncs-and-holds-back-the-others) | A mirror folder too large to finish in one run never syncs, and holds back the others |
| [B66](#b66--local-only-pending-data-is-not-protected-at-shutdown-high-21) | Local-only pending data is not protected at shutdown (HIGH-21) |
@@ -308,6 +309,7 @@ a live account since.
| Entry | Title |
|---|---|
| [B295](#b295--a-resize-the-scratch-file-refused-still-succeeded) | A resize the scratch file refused still succeeded |
| [B293](#b293--a-large-trash-never-lists-and-empty-trash-never-empties-it) | A large trash never lists, and Empty Trash never empties it |
| [B292](#b292--two-programs-changing-settings-at-once-lose-one-of-the-changes) | Two programs changing settings at once lose one of the changes |
| [B290](#b290--reopening-the-database-right-after-closing-it-can-be-refused-as-another-daemon) | Reopening the database right after closing it can be refused as another daemon |
@@ -398,6 +400,53 @@ a live account since.
Newest first.
### B297 — The simulations fail and hang when run in parallel, and nothing stops that
**Status:** Fixed (unverified)
**Found:** 2026-11-25, while running the full simulation suite several times each for #134, #135
and the 4.0 crate moves, with `cargo test -p pdfs-fuse --lib -- --ignored sim::`. That command
leaves out `--test-threads=1`, which CI and [TESTING.md](TESTING.md) use, so libtest ran up to
eight simulations at once in one process.
**Where:** `crates/pdfs-fuse/src/sim/daemon.rs`, `Daemon::start` and `Daemon::shut_down`
**Repro:** Run the suite without `--test-threads=1`. Of 18 such runs on three branches based on
main, 6 passed, 10 failed and 2 hung until a 900 s timeout. The failures were timing asserts
in many tests, among them `a_write_that_failed_on_a_short_outage_goes_out_soon_after_the_link_returns`,
`three_clients_one_writer_each` and `one_client_with_stale_hashes_and_reordered_echoes`.
Each passes when run alone.
In a hung run, one test thread stayed in state D in `request_wait_answer`, waiting on a FUSE
request to a mount its own process serves. Killing the process left it a zombie and left its
mounts in place until their connections were aborted through
`/sys/fs/fuse/connections/<n>/abort`.
Run serially, the same branches pass in CI (#133 to #137).
**Cause.** The simulations share process-wide state: `isolate_from_the_developer` sets the XDG
variables once, which is sound only while no other test reads the environment, and every
daemon runs drain workers, a sync engine and a runtime on the same few cores. In parallel the
timing asserts miss their deadlines, and the harness has no way out of a mount that stops
answering.
**Fix.** `Daemon::start` takes a turn: a daemon started on one test thread waits while
another test thread still has one, so plain `cargo test` runs the simulations one after the
other. A daemon on the same thread, as in a restart or the multi-client runs, does not wait.
`--test-threads=1` stays the documented way, because it also keeps the parts of a test
before its first daemon apart.
A mount that does not stop within 60 s has its FUSE connection aborted through
`/sys/fs/fuse/connections/<n>/abort`, which the mounting user may write, and the stop fails
with that message. A daemon alive after 20 minutes gets the same, so a test blocked on a
request the mount never answers fails with `ENOTCONN` instead of hanging the run.
**Verified:** `a_simulation_on_another_thread_waits_for_this_ones_daemons`, which fails
without the turn.
Separately, CI on main (`0b9e849`) failed `a_move_blocked_by_trash_can_be_retried_after_restore`
once, serially ([run](https://github.com/narrrl/proton-drive-linux/actions/runs/45694939718)):
the assert at `daemon.rs:2209` found an empty list. It has not failed since.
---
### B296 — A busy database stalls reads, and piles up diagnostics threads
**Status:** Fixed (unverified)