-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception from RabbitMQ is treated as "user-unhandled" and stops Aspire app execution #4755
Comments
This has been this way since the very beginning right? I was talking to @eerhardt about this just recently. The RabbitMQ client causes the debugger to break on every failed connection attempt until RabbitMQ is ready. Would be great to understand why though, as when we looked at this originally it wasn't obvious what the cause was as the logic is in a retry loop with an exception handler. |
Possibly. I suspect the latest Visual Studio previews have been more aggressive in terms of re-setting Just My Code option to enabled, which is why I noticed this issue now. That said, something seems wrong--the execution of the program seems to stop for no good reason. Either the RabbitMQ client should handle the exception better, or Visual Studio is unnecessarily stopping when this exception is thrown (when Just My Code=true). |
I can reproduce this behavior outside of Aspire by <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
<PackageReference Include="Polly.Core" Version="8.4.1" />
</ItemGroup>
</Project> using Polly;
using Polly.Retry;
using RabbitMQ.Client;
using RabbitMQ.Client.Exceptions;
using System.Net.Sockets;
var factory = new ConnectionFactory();
factory.Uri = new Uri("amqp://guest:guest@localhost:5672");
CreateConnection(factory, 3);
static IConnection CreateConnection(IConnectionFactory factory, int retryCount)
{
var resiliencePipelineBuilder = new ResiliencePipelineBuilder();
if (retryCount > 0)
{
resiliencePipelineBuilder.AddRetry(new RetryStrategyOptions
{
ShouldHandle = static args => args.Outcome is { Exception: SocketException or BrokerUnreachableException }
? PredicateResult.True()
: PredicateResult.False(),
BackoffType = DelayBackoffType.Exponential,
MaxRetryAttempts = retryCount,
Delay = TimeSpan.FromSeconds(1),
});
}
var resiliencePipeline = resiliencePipelineBuilder.Build();
return resiliencePipeline.Execute(factory =>
{
try
{
return factory.CreateConnection();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
throw;
}
}, factory);
} @BillHiebert - can someone on the VS Debugger take a look here? I don't think there is anything we can do from the Aspire side. One interesting side note is that the exception ToString() is getting written to the console before VS breaks. The app is stopped, at line |
@gregg-miskelly Is this expected with Just My Code? With Erik's example, if I just run the app it crashes at the end since it throws out of the entry point and is expected. If I debug with just my code disable, the program runs and only breaks on the final unhandled exception. But with just my code enabled, it breaks on the external throw out of RabbitMQ - all 3 since Erik's example has 3 retries:
|
This is currently "By Design" -- the exception is travelling through user code and presumably being caught by Poly (system code), so the debugger will stop. There is currently a .NET 9 API proposal that would potentially address this if Poly was updated to take advantage of it (and the proposal landed on something that would work for Poly) -- dotnet/runtime#103105 |
Thanks, everyone, much appreciated. I guess I am going to close this issue, and maybe open a new one for Polly if/when dotnet/runtime#103105 lands. |
Repro steps
Expected
The app should start normally
Actual
The following exception is reported as "user-unhandled" and the execution stops
Additional info
This does NOT repro (execution continues normally) if Just My Code is turned off
FYI @DamianEdwards
The text was updated successfully, but these errors were encountered: