is it possible to configure the Yarp.ReverseProxy.Forwarder.HttpForwarder, so that I can set a timeout for the HttpForwarder? This is a code snippet from Program.cs. The configurations are in appsettings.json. The HTTP forwarder is not explicitly configured.
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("section from appsettings"))
...
var app = builder.Build();
...
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.Run();
The problem is this python script:
...
import requests
import urllib3
...
print(requests.get('https://yarp.xyz/interestingsite', headers=headers, verify=False))
time.sleep(0.0)
print(requests.get('https://yarp.xyz/abc.css', headers=headers, verify=False))
...
When I increase the sleeping time from 0.0 to 0.5 The scripts works and I get the css file. Otherwise I get an exception from the forwarder. Kestrel returns 502 http status code.
Have also checked https://github.com/microsoft/reverse-proxy/discussions/2183. Do I have to explictly define a the forwarder and configure it in the code instead of the appsettings.json?
Error message:
info: Yarp.ReverseProxy.Forwarder.HttpForwarder[48]
Request: An error was encountered before receiving a response.
System.Net.Http.HttpRequestException: An error occurred while sending the request.
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
--- End of inner exception stack trace ---
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at Yarp.ReverseProxy.Forwarder.HttpForwarder.SendAsync(HttpContext context, String destinationPrefix, HttpMessageInvoker httpClient, ForwarderRequestConfig requestConfig, HttpTransformer transformer, CancellationToken cancellationToken)