Files
Febe/src/Febe.Data/CommandScope.cs
T
Alby96andClaude Opus 5.5 0775a1460f
verifica / controlli (push) Successful in 25s
verifica / prove (push) Successful in 25m9s
verifica / installatore (push) Successful in 7m37s
verifica / immagine (push) Successful in 20m21s
Prove che cadevano con il runner carico (#46)
Le prove cadevano a ogni carico della CI, ogni volta prove diverse. Dietro alcune c'erano
difetti veri: FebeDatabase lasciava i file aperti dopo DisposeAsync (comandi SQLite non
chiusi, pool di lettura chiuso dopo lo scrittore), e il WAL spariva durante lo spostamento
della cartella Dati; la scheda dell'account senza statistiche leggeva i file di tutta la
libreria; l'arresto di FebeApp non aspettava i lavori aggiunti da un avvio in corso.
Chromium ha 120 s per avviarsi e aprire la prima scheda, e il ricollegamento smette appena
il processo cambia.

Nelle prove i limiti di tempo diventano protezioni contro un blocco: attese per condizione
con un aiuto comune, limiti per classe nella prova di scala con il tempo migliore, porta 0 e
stderr di Chromium nel browser delle prove, e la prova di «Scollega» di WebView2 controlla
che il processo esca davvero. Provato su Windows con tutti i core occupati.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 19:50:40 +01:00

38 lines
1.4 KiB
C#

using Microsoft.Data.Sqlite;
namespace Febe.Data;
/// <summary>
/// Keeps the commands that <see cref="Sql.Command"/> creates on this thread while a read runs, and disposes them when the
/// read ends. Reads build their commands inline (<c>c.Command(...).ExecuteReader()</c>); left to the garbage collector,
/// a command keeps its SQLite statement alive until the finalizer runs, so the connection closed by
/// <see cref="FebeDatabase.DisposeAsync"/> would only really close then, keeping the files open (#46).
/// </summary>
internal sealed class CommandScope : IDisposable
{
[ThreadStatic]
private static CommandScope? t_current;
private readonly CommandScope? _outer;
private readonly List<SqliteCommand> _commands = [];
private CommandScope(CommandScope? outer) => _outer = outer;
/// <summary>Starts tracking the commands created on this thread until the scope is disposed.</summary>
public static CommandScope Begin() => t_current = new CommandScope(t_current);
/// <summary>Adds <paramref name="command"/> to the open scope of this thread, if any.</summary>
public static void Track(SqliteCommand command) => t_current?._commands.Add(command);
public void Dispose()
{
t_current = _outer;
foreach (var command in _commands)
{
command.Dispose();
}
_commands.Clear();
}
}