Skip to content

Message Timeouts

You don't want your Wolverine application to effectively become non-responsive by a handful of messages that accidentally run in an infinite loop and therefore block all other message execution. To that end, Wolverine let's you enforce configurable execution timeouts. Wolverine does this through the usage of setting a timeout on a CancellationToken used within the message execution. To play nicely with this timeout, you should take in CancellationToken in your asynchronous message handler methods and use that within asynchronous method calls.

When a timeout occurs, a TaskCanceledException will be thrown.

To override the default message timeout of 60 seconds, use this syntax at bootstrapping time:

using var host = await Host.CreateDefaultBuilder()
    .UseWolverine(opts => { opts.DefaultExecutionTimeout = 1.Minutes(); }).StartAsync();

snippet source | anchor

To override the message timeout on a message type by message type basis, you can use the [MessageTimeout] attribute as shown below:

public async Task Handle(PotentiallySlowMessage message, CancellationToken cancellationToken)

snippet source | anchor

Released under the MIT License.