Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Temporalio/Worker/TemporalWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,11 @@ public Task ExecuteAsync(CancellationToken stoppingToken) =>
public Task ExecuteAsync(
Func<Task> untilComplete, CancellationToken stoppingToken = default) =>
ExecuteInternalAsync(
() => untilComplete().ContinueWith(

@cretz cretz Jan 22, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, it is confusing that .NET doesn't really have a "map-on-success" combinator and that continue-with inadvertently swallows failures here. Thanks for the fix!

I see one other place we'll need to fix this type of thinking (Temporalio.Workflows.Semaphore for a failure in a wait condition), but we can handle that in a separate issue, no worries.

_ => ValueTuple.Create(),
default,
TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion,
TaskScheduler.Current),
async () =>
{
await untilComplete().ConfigureAwait(false);
return ValueTuple.Create();
},
stoppingToken);

/// <summary>
Expand Down
39 changes: 39 additions & 0 deletions tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Temporalio.Worker;
using Temporalio.Workflows;
using Xunit;
using Xunit.Abstractions;

namespace Temporalio.Tests.Worker;

public class GeneralWorkerTests : TestBase
{
public GeneralWorkerTests(ITestOutputHelper output)
: base(output)
{
}

[Workflow]
public class VoidWorkflow
{
[WorkflowRun]
public async Task RunAsync()
{
}
}

[Fact]
public async Task ExecuteAsync_VoidWorkflowFailure_PropagatesException()
{
// This test verifies that ExecuteAsync(Func<Task>) properly propagates exceptions
// from void-returning tasks. This is a regression test for a bug where
// ContinueWith with OnlyOnRanToCompletion caused exceptions to be swallowed.
await using var env = await Temporalio.Testing.WorkflowEnvironment.StartLocalAsync();
Comment thread
adeal marked this conversation as resolved.
Resolved
using var worker = new TemporalWorker(
env.Client,
new TemporalWorkerOptions($"tq-{Guid.NewGuid()}").AddWorkflow<VoidWorkflow>());
Comment thread
adeal marked this conversation as resolved.
Resolved

// Throw an arbitrary exception type to verify it is propagated out of the worker execution.
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
await worker.ExecuteAsync(async () => throw new InvalidOperationException(null)));
}
}
Loading