RequestClient receives TimeOutException instead of RequestFaultException
See original GitHub issueIs this a bug report?
Update: I’m not sure
Can you also reproduce the problem with the latest version?
Yes
Environment
- Operating system: Windows 10
- Visual Studio version: Visual Studio 2017
- Dotnet version: .NET Framework 4.6.2
Steps to Reproduce
Given following Code:
using System;
using System.Security;
using System.Threading.Tasks;
using MassTransit;
namespace ConsoleApp4
{
class Program
{
private static string QUEUE_NAME = "some.test.queue";
static void Main(string[] args)
{
var bus = Bus.Factory.CreateUsingRabbitMq(sbc =>
{
var host = sbc.Host(new Uri("rabbitmq://localhost:/"), h =>
{
h.Username("guest");
h.Password("guest");
});
sbc.ReceiveEndpoint(host, QUEUE_NAME, endpoint =>
{
endpoint.Consumer<MyMessageConsumer>();
});
});
Task.WaitAll(bus.StartAsync());
var requestClient = bus.CreateRequestClient<MyMessage, MyResponse>(new Uri($"rabbitmq://localhost:/{QUEUE_NAME}"), TimeSpan.FromSeconds(5));
try
{
var result = requestClient.Request(new MyMessage {Value = "Hello, World."}).GetAwaiter().GetResult();
Console.WriteLine("Got Result from Service: {0}", result.Value);
}
catch (Exception ex)
{
Console.WriteLine("got exception {0}", ex.GetType());
// TimeOut-Exception instead of RequestFaultException?
}
Console.ReadLine();
Task.WaitAll(bus.StopAsync());
}
}
class MyMessageConsumer : IConsumer<MyMessage>
{
public Task Consume(ConsumeContext<MyMessage> context)
{
// throw a readable exception, which the request-client should read
throw new SecurityException("Client should please read this");
// return context.RespondAsync(new MyResponse { Value = context.Message.Value });
}
}
class MyMessage
{
public string Value { get; set; }
}
class MyResponse
{
public string Value { get; set; }
}
}
Expected Behavior
The RequestClient should get a RequestFaultedException, with the actual exception in it.
Actual Behavior
A Timeout-Exception occurs instead of a RequestFaultedException
This worked in 3.5.7 before updating to 5.3.2 (i know, big step). We’re using the request-client on many, many places in our code and our GlobalExceptionHandler handled these RequestFaults before, and now it can’t because a timeoutexception occurs instead.
Update:: My sample throws a timeoutexception too, on version 3.5.7, so I’m not sure, whats happening…
Reproducible Demo
See Steps to Reproduce Issue https://github.com/MassTransit/MassTransit/issues/1006 seems to be identical.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
(Request/response) Request not receiving an exception ...
On the Request/Response ideia... I have a handler: public class AutenticacaoHandler : IConsumer { public async Task Consume(ConsumeContext ...
Read more >How to catch timeout exception in Spring WebClient?
1 Answer. From java doc: Switch to a fallback Mono in case no item arrives within the given Duration. If the fallback Mono...
Read more >How to Avoid java.util.concurrent. TimeoutException
The java.util.concurrent.TimeoutException is thrown when a blocking operation times out. Learn how to avoid it.
Read more >TimeoutException (Java Platform SE 8 )
Exception thrown when a blocking operation times out. Blocking operations for which a timeout is specified need a means to indicate that the...
Read more >TimeoutException Class (System)
Initializes a new instance of the TimeoutException class with the specified error message and inner exception. Properties. Data. Gets a collection of key/value ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes, any blocking code in the async/TPL world causes random issues.
closing this, as it seems I fixed the issue at our code-base with refactoring the “async” code and removing all the blocking .result code.
Thank you!