0xMiden / 0xMiden/note-transport-service

Maintenance loop spins with no delay when cleanup fails

Open Beginner friendly
#95 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
3
Forks
10
Avg merge
2h 23m
Merged PRs (30d)
4

Description

I was reading through the db maintenance code and I think there's a problem with the loop when the cleanup step fails.

In `entrypoint` the loop just keeps calling `step()`:

```rust
while self.is_active() {
if let Err(e) = self.step().await {
error!("Database maintenance error: {e}");
}
}
```

And `step()` does the cleanup first and only sleeps at the very end:

```rust
let deleted = self.database.cleanup_old_notes(self.config.retention_days).await?;
info!(...);
timer.finish("ok");
sleep(Duration::from_secs(600)).await;
```

The sleep is the last line, after the `?`. So if `cleanup_old_notes` returns an error (db locked, disk full, corrupt file, etc.), `step()` returns early and the sleep never runs. The loop just logs the error and calls `step()` again straight away.

If the error keeps happening this becomes a tight loop with no wait between tries. It pins the CPU and floods the logs, which is extra bad when the disk is already full.

I think the sleep should run between every iteration, even when cleanup fails. The simplest fix is to move the interval sleep into the loop in `entrypoint` so it always runs. (Small extra thing: on the error path the `timer` is also dropped without calling `finish`.)

Code: [maintenance.rs](https://github.com/0xMiden/note-transport-service/blob/main/crates/node/src/database/maintenance.rs#L35-L59)

Happy to work on this if you can assign it to me.

Contributor guide

Open the contributing guide

Research direction

The issue is in crates/node/src/database/maintenance.rs. Look at the entrypoint loop and the step method. The sleep should be moved to always execute, even after an error. Start by reading the linked code lines 35-59, understand the flow, and ensure the timer is properly handled on error paths. A test run of the maintenance loop would verify the fix prevents a tight loop.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, databases
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.