0xMiden / 0xMiden/note-transport-service
Maintenance loop spins with no delay when cleanup fails
- Langage dominant
- Rust
- Étoiles
- 3
- Forks
- 10
- Merge moyen
- 2 h 23 min
- PR mergées (30 j)
- 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.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Le problème se trouve dans crates/node/src/database/maintenance.rs. Examinez la boucle du point d'entrée et la méthode step. Le sleep doit être déplacé pour s'exécuter toujours, même après une erreur. Commencez par lire les lignes de code liées 35-59, comprenez le flux et assurez-vous que le minuteur est correctement géré sur les chemins d'erreur. Un test d'exécution de la boucle de maintenance vérifierait que la correction empêche une boucle serrée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- rust
- Domaine
- backend, databases
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- Calme
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 70/100