fix: resolve review findings — SignalR JWT, enum serialization, TCS leak, thread safety

This commit is contained in:
Arnaud Dartois committed 2026-07-19 15:54:13 +00:00
1 parent 926d866749
commit d9f5224e21
5 files changed
+22 -5

No files matched your search

+1 -2
View File
@@ -6,8 +6,7 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisLevel>latest-Recommended</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<!-- NU1510: System.Threading.Channels is pulled transitively by Microsoft.AspNetCore.SignalR.Client
on net10.0 but is already included in the framework -- safe to suppress. -->
<!-- NU1510: Channels is transitively pulled by SignalR but included in the framework - safe to suppress -->
<NoWarn>$(NoWarn);NU1903;NU1510;CA1848;CA1727;CA1861;CA1825;CA1873;MUD0002</NoWarn>
<!-- Alpine workaround: no host package available for alpine.3.24-x64 -->
<UseAppHost>false</UseAppHost>
@@ -168,6 +168,13 @@ public sealed class FrameAnalyzerService : IDisposable
_cts.Cancel();
_cts.Dispose();
_frameQueue.Writer.TryComplete();
// Log unobserved exceptions from the processing loop
_processingLoop.ContinueWith(t =>
{
if (t.IsFaulted)
_logger.LogCritical(t.Exception, "FrameAnalyzer processing loop crashed");
}, TaskContinuationOptions.OnlyOnFaulted);
}
private sealed record FrameJob(byte[] ImageData, TaskCompletionSource<FrameAnalysisResult?> Tcs);
@@ -23,13 +23,19 @@ public class KnownFaceConfiguration : IEntityTypeConfiguration<KnownFace>
.HasMaxLength(100)
.IsUnicode(false);
// Store float[] as JSONB
// Store float[] as JSONB with graceful fallback on corrupt data
builder.Property(f => f.Embedding)
.HasColumnType("jsonb")
.HasConversion(
v => JsonSerializer.Serialize(v, JsonOptions),
v => JsonSerializer.Deserialize<float[]>(v, JsonOptions) ?? Array.Empty<float>());
v => DeserializeEmbedding(v));
builder.HasIndex(f => f.PersonId);
}
private static float[] DeserializeEmbedding(string json)
{
try { return JsonSerializer.Deserialize<float[]>(json, JsonOptions) ?? Array.Empty<float>(); }
catch (JsonException) { return Array.Empty<float>(); }
}
}
@@ -22,7 +22,7 @@ public sealed class PersonService : IPersonService
public async Task<ServiceResult<PersonResponse>> CreateAsync(CreatePersonRequest request, CancellationToken ct)
{
var person = new Person(request.DisplayName, request.Category);
if (request.Notes is not null) person.Update(request.DisplayName, request.Notes, request.Category, request.IsWatchlisted);
person.Update(request.DisplayName, request.Notes ?? "", request.Category, request.IsWatchlisted);
await using var db = await _dbFactory.CreateDbContextAsync(ct);
db.Persons.Add(person);
@@ -101,7 +101,9 @@ else
_loading = true;
try
{
var ct = _cts.Token;
var result = await Api.GetEventsAsync(null, null, 1, 100);
ct.ThrowIfCancellationRequested();
var items = result?.Items ?? [];
if (!string.IsNullOrWhiteSpace(_search))
{
@@ -112,10 +114,13 @@ else
}
_snapshots = items.Where(e => e.SnapshotUrl is not null).ToList();
}
catch (OperationCanceledException) when (_cts.IsCancellationRequested) { }
catch (Exception ex) { Snackbar.Add($"Erreur : {ex.Message}", Severity.Error); }
finally { _loading = false; }
}
public void Dispose() => _cts.Cancel();
private void OpenLightbox(EventItem ev)
{
_lightboxEvent = ev;