Closed Spaceman1861 closed 4 years ago
Thanks for opening this.
Couple of questions:
I will review both your questions and get back to you.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
Sorry for the long delay on this.
I have generated this repro that demonstrates that httpclientfactory alone is no the issue.
[assembly: FunctionsStartup(typeof(Startup))]
namespace _6029Repro
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddHttpClient();
}
}
}
namespace _6029Repro
{
public class ReleaseManagerTimerFunctionNoMediator
{
private readonly IHttpClientFactory _httpClientFactory;
public ReleaseManagerTimerFunctionNoMediator(IHttpClientFactory httpClientFactory) =>
_httpClientFactory = httpClientFactory;
[FunctionName(nameof(ReleaseManagerTimerFunctionNoMediator))]
public async Task Run(
//[TimerTrigger("0 20 * * *")]
[TimerTrigger("* * * * *")] TimerInfo timerInfo
)
{
HttpClient clientA;
HttpClient clientB;
const string clientAEndpoint = "https://api.nasa.gov/planetary/apod";
const string clientBEndpoint = "https://ssd-api.jpl.nasa.gov/fireball.api";
clientA = _httpClientFactory.CreateClient(nameof(clientA));
clientB = _httpClientFactory.CreateClient(nameof(clientB));
var clientAResponse = await clientA.GetAsync(clientAEndpoint);
var clientBResponse = await clientB.GetAsync(clientBEndpoint);
Console.WriteLine(await clientAResponse.Content.ReadAsStringAsync());
Console.WriteLine(await clientBResponse.Content.ReadAsStringAsync());
}
}
}
That works fine.
Oddly I cannot replicate this anymore.
I have updated dotnet runtime since to 3.1.5 so maybe that fixed it :|
This works for me now.
[assembly: FunctionsStartup(typeof(Startup))]
namespace _6029Repro
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddHttpClient();
builder.Services.AddMediatR(typeof(Startup));
}
}
public class ReleaseManagerTimerFunctionNoMediator
{
private readonly IMediator _mediator;
public ReleaseManagerTimerFunctionNoMediator(IMediator mediator) =>
_mediator = mediator;
[FunctionName(nameof(ReleaseManagerTimerFunctionNoMediator))]
public async Task Run(
//[TimerTrigger("0 20 * * *")]
[TimerTrigger("* * * * *")] TimerInfo timerInfo
)
{
await _mediator.Send(new ParentRequest());
}
}
public class ParentRequest : IRequest { }
public class ClientARequest : IRequest { }
public class ClientBRequest : IRequest { }
public class ParentHandler : IRequestHandler<ParentRequest>
{
private readonly IMediator _mediator;
public ParentHandler(IMediator mediator) =>
_mediator = mediator;
public async Task<Unit> Handle(ParentRequest request, CancellationToken cancellationToken = default)
{
await _mediator.Send(new ClientARequest(), cancellationToken);
await _mediator.Send(new ClientBRequest(), cancellationToken);
return Unit.Value;
}
}
public class ClientARequestHandler : IRequestHandler<ClientARequest>
{
private readonly IHttpClientFactory _httpClientFactory;
public ClientARequestHandler(IHttpClientFactory httpClientFactory) =>
_httpClientFactory = httpClientFactory;
public async Task<Unit> Handle(ClientARequest request, CancellationToken cancellationToken = default)
{
HttpClient clientA;
const string clientAEndpoint = "https://api.nasa.gov/planetary/apod";
clientA = _httpClientFactory.CreateClient(nameof(clientA));
var clientAResponse = await clientA.GetAsync(clientAEndpoint, cancellationToken);
Console.WriteLine(await clientAResponse.Content.ReadAsStringAsync());
return Unit.Value;
}
}
public class ClientBRequestHandler : IRequestHandler<ClientBRequest>
{
private readonly IHttpClientFactory _httpClientFactory;
public ClientBRequestHandler(IHttpClientFactory httpClientFactory) =>
_httpClientFactory = httpClientFactory;
public async Task<Unit> Handle(ClientBRequest request, CancellationToken cancellationToken = default)
{
HttpClient clientB;
const string clientBEndpoint = "https://ssd-api.jpl.nasa.gov/fireball.api";
clientB = _httpClientFactory.CreateClient(nameof(clientB));
var clientBResponse = await clientB.GetAsync(clientBEndpoint, cancellationToken);
Console.WriteLine(await clientBResponse.Content.ReadAsStringAsync());
return Unit.Value;
}
}
}
Im going to close for now
Hi all,
I have been having some issues with a Dryloc Exception(detail below). The exact same application in a console app works correctly.
I have posted this issue on the Mediatr GitHub think the issue may lay there but the creator is of the opinion that it is not. https://github.com/jbogard/MediatR/issues/516#event-3327307606
Investigative information
Happens every time in local debug or deployed
Repro steps
Call
await Mediatr.Send()
twiceExpected behavior
No exception
Actual behavior
Exception
Known workarounds
Using .GetAwaiter().GetResult(); or .Wait();
Related information
Using these packages:
With this function:
Which calls this handler
Which in turn calls these (simplifed for debugging):