JeringTech / Javascript.NodeJS

Invoke Javascript in NodeJS, from C#
Other
463 stars 43 forks source link

Getting error System.Net.Http.HttpRequestException: An error occurred while sending the request for a long duration request on a Linux docker #113

Closed irfanamd closed 3 years ago

irfanamd commented 3 years ago

I am running a request that takes more than 10 minutes. The same request works fine when I run it locally on my Windows machine. But when the solution is deployed in a docker, it gives this error after around 4 minutes. I suspect some timeout is triggering and aborting connection. I am using Node 12.x for my purpose. Any idea?

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: The request was aborted. ---> System.IO.IOException: The response ended prematurely, with at least 9 additional bytes expected. at System.Net.Http.Http2Connection.ReadAtLeastAsync(Stream stream, Memory1 buffer, Int32 minReadBytes) at System.Net.Http.Http2Connection.EnsureIncomingBytesAsync(Int32 minReadBytes) at System.Net.Http.Http2Connection.ReadFrameAsync(Boolean initialFrame) at System.Net.Http.Http2Connection.ProcessIncomingFramesAsync() --- End of inner exception stack trace --- at System.Net.Http.Http2Connection.Http2Stream.CheckResponseBodyState() at System.Net.Http.Http2Connection.Http2Stream.TryEnsureHeaders() at System.Net.Http.Http2Connection.Http2Stream.ReadResponseHeadersAsync(CancellationToken cancellationToken) at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at Jering.Javascript.NodeJS.HttpNodeJSService.TryInvokeAsync[T](InvocationRequest invocationRequest, CancellationToken cancellationToken) at Jering.Javascript.NodeJS.OutOfProcessNodeJSService.TryInvokeCoreAsync[T](InvocationRequest invocationRequest, CancellationToken cancellationToken) at Jering.Javascript.NodeJS.OutOfProcessNodeJSService.InvokeFromFileAsync[T](String modulePath, String exportName, Object[] args, CancellationToken cancellationToken)

JeremyTCD commented 3 years ago

Hi, could you try setting TimeoutMS to -1?

It is ~10 minutes~ 1 minute by default, so the fact that yours is erroring out at 4 minutes is odd. Worth trying though.

Docs on configuring.

irfanamd commented 3 years ago

It is already set to -1. But even it doesn't reach the 10 mins limit.

JeremyTCD commented 3 years ago

I see. Could you run a minimal repro that just waits for 10 minutes in your container? If it still fails at ~4mins we can rule out application code issues.

class Program
{
    static async Task Main()
    {
        string javascriptModule = @"
module.exports = (callback) => {
    setTimeout(() => callback(null, 'success'), 600000);
}";
        StaticNodeJSService.Configure<OutOfProcessNodeJSServiceOptions>(options => options.TimeoutMS = -1);
        string result = await StaticNodeJSService.InvokeFromStringAsync<string>(javascriptModule);
        Console.WriteLine(result);
    }
}

Edit: Previous example wasn't great. The code above will work.

irfanamd commented 3 years ago

Looks like the issue was with the application code probably the process is exhausting allocated memory and crashing as a result. I suppose you can mark the issue closed.

P.S. Is it possible to digitally sign the NuGet package generated for this project?

JeremyTCD commented 3 years ago

Okay cool, closing since resolved.

digitally sign the NuGet package

Last time I looked into it I didn't think a certificate was worth it. How important is this for you?

irfanamd commented 3 years ago

Well important for us but if it's not possible or not worth your efforts then leave it. Thanks