fix(worker): DeleteTask aus der UI schlug immer mit generischem Serverfehler fehl

Der CancellationToken-Parameter auf der nicht-streamenden Hub-Methode liess SignalR jede Invocation vor dem Methodenrumpf abbrechen. Die Tests riefen den Hub direkt auf und sahen das nicht; neuer Reflection-Guard verbietet CancellationToken auf allen nicht-streamenden Hub-Methoden.
This commit is contained in:
mika kuns
2026-09-28 13:02:47 +02:00
parent c8b2ad046a
commit 352aaa525b
2 changed files with 24 additions and 5 deletions
+4 -1
View File
@@ -277,8 +277,11 @@ public sealed class WorkerHub : Microsoft.AspNetCore.SignalR.Hub
// TryAdvanceParentAsync side effect — a direct-repo delete from the details pane // TryAdvanceParentAsync side effect — a direct-repo delete from the details pane
// used to skip it, permanently wedging a WaitingForChildren parent whose last // used to skip it, permanently wedging a WaitingForChildren parent whose last
// child was deleted from there. // child was deleted from there.
public async Task DeleteTask(string taskId, CancellationToken cancellationToken) // No CancellationToken parameter: SignalR can't bind one on a non-streaming method and fails
// every invocation with a generic server error before the body runs.
public async Task DeleteTask(string taskId)
{ {
var cancellationToken = CancellationToken.None;
await using var ctx = await _dbFactory.CreateDbContextAsync(cancellationToken); await using var ctx = await _dbFactory.CreateDbContextAsync(cancellationToken);
var repo = new TaskRepository(ctx); var repo = new TaskRepository(ctx);
var task = await repo.GetByIdAsync(taskId, cancellationToken) var task = await repo.GetByIdAsync(taskId, cancellationToken)
@@ -66,7 +66,7 @@ public sealed class DeleteTaskHubTests : IDisposable
var (parentId, childId) = await SeedParentWithChildAsync(TaskStatus.Idle); var (parentId, childId) = await SeedParentWithChildAsync(TaskStatus.Idle);
var hub = CreateHub(); var hub = CreateHub();
await hub.DeleteTask(childId, default); await hub.DeleteTask(childId);
await using var ctx = _db.CreateContext(); await using var ctx = _db.CreateContext();
Assert.Null(await ctx.Tasks.FindAsync(childId)); Assert.Null(await ctx.Tasks.FindAsync(childId));
@@ -80,7 +80,7 @@ public sealed class DeleteTaskHubTests : IDisposable
var (_, childId) = await SeedParentWithChildAsync(TaskStatus.Running); var (_, childId) = await SeedParentWithChildAsync(TaskStatus.Running);
var hub = CreateHub(); var hub = CreateHub();
await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask(childId, default)); await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask(childId));
await using var ctx = _db.CreateContext(); await using var ctx = _db.CreateContext();
Assert.NotNull(await ctx.Tasks.FindAsync(childId)); Assert.NotNull(await ctx.Tasks.FindAsync(childId));
@@ -92,7 +92,7 @@ public sealed class DeleteTaskHubTests : IDisposable
var (parentId, _) = await SeedParentWithChildAsync(TaskStatus.Idle); var (parentId, _) = await SeedParentWithChildAsync(TaskStatus.Idle);
var hub = CreateHub(); var hub = CreateHub();
var ex = await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask(parentId, default)); var ex = await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask(parentId));
Assert.Contains("child tasks", ex.Message, StringComparison.OrdinalIgnoreCase); Assert.Contains("child tasks", ex.Message, StringComparison.OrdinalIgnoreCase);
} }
@@ -102,6 +102,22 @@ public sealed class DeleteTaskHubTests : IDisposable
{ {
var hub = CreateHub(); var hub = CreateHub();
await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask("does-not-exist", default)); await Assert.ThrowsAsync<HubException>(() => hub.DeleteTask("does-not-exist"));
}
/// <summary>A CancellationToken on a non-streaming hub method breaks SignalR binding (every call fails with a generic server error); direct-call tests can't see that.</summary>
[Fact]
public void NoNonStreamingHubMethod_TakesCancellationToken()
{
var offenders = typeof(WorkerHub)
.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.DeclaredOnly)
.Where(m => !m.IsSpecialName)
.Where(m => !(m.ReturnType.IsGenericType && m.ReturnType.GetGenericTypeDefinition() is var g
&& (g == typeof(IAsyncEnumerable<>) || g == typeof(System.Threading.Channels.ChannelReader<>))))
.Where(m => m.GetParameters().Any(p => p.ParameterType == typeof(CancellationToken)))
.Select(m => m.Name)
.ToList();
Assert.Empty(offenders);
} }
} }