Skip to content
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

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. #187

Closed
CallumVass opened this issue Dec 1, 2023 · 1 comment

Comments

@CallumVass
Copy link

Hi,

If I start send multiple requests at once, after a while I will occasionally start seeing this error and then the invocation of the javascript will start taking around 2 seconds to complete until I restart my .NET server.

info: System.Net.Http.HttpClient.IHttpClientService.LogicalHandler[100]
      Start processing HTTP request POST http://[::1]:54391/
info: System.Net.Http.HttpClient.IHttpClientService.ClientHandler[100]
      Sending HTTP request POST http://[::1]:54391/
warn: Jering.Javascript.NodeJS.HttpNodeJSService[0]
      An invocation attempt failed. Retries using existing process remaining: 1.
      Exception:
        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.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
         at System.Net.Http.HttpConnection.InitialFillAsync(Boolean async)
         at System.Net.Http.HttpConnection.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at System.Net.Http.HttpConnection.SendAsync(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 System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
         at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
         at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
         at Jering.Javascript.NodeJS.HttpNodeJSService.TryInvokeAsync[T](InvocationRequest invocationRequest, CancellationToken cancellationToken)
         at Jering.Javascript.NodeJS.OutOfProcessNodeJSService.TryInvokeCoreAsync[T](InvocationRequest invocationRequest, CancellationToken cancellationToken)
info: System.Net.Http.HttpClient.IHttpClientService.LogicalHandler[100]
      Start processing HTTP request POST http://[::1]:54391/
info: System.Net.Http.HttpClient.IHttpClientService.ClientHandler[100]
      Sending HTTP request POST http://[::1]:54391/
fail: Jering.Javascript.NodeJS.HttpNodeJSService[0]
      Starting inspector on 127.0.0.1:9229 failed: address already in use

warn: Jering.Javascript.NodeJS.HttpNodeJSService[0]
      An invocation attempt failed. Retries using existing process remaining: 0.
      Exception:
        System.Net.Http.HttpRequestException: No connection could be made because the target machine actively refused it. ([::1]:54391)
       ---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
         at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
         at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
         at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem)
         at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(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 System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
         at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
         at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
         at Jering.Javascript.NodeJS.HttpNodeJSService.TryInvokeAsync[T](InvocationRequest invocationRequest, CancellationToken cancellationToken)
         at Jering.Javascript.NodeJS.OutOfProcessNodeJSService.TryInvokeCoreAsync[T](InvocationRequest invocationRequest, CancellationToken cancellationToken)
warn: Jering.Javascript.NodeJS.HttpNodeJSService[0]
      Retries in existing process exhausted. Process retries remaining: 1.
dbug: Jering.Javascript.NodeJS.HttpNodeJSService[0]
      Waiting on process connection semaphore, processID: 106004, thread ID: 127, thread is ThreadPool thread : True.
info: Jering.Javascript.NodeJS.HttpNodeJSService[0]
      Connected to NodeJS through HTTP/1.1. Endpoint: http://[::1]:55804/.
info: Jering.Javascript.NodeJS.HttpNodeJSService[0]
      Connected to NodeJS process: 106004.
dbug: Jering.Javascript.NodeJS.HttpNodeJSService[0]
      Releasing process connection semaphore, processID: 106004, thread ID: 134, thread is ThreadPool thread : False.
dbug: Jering.Javascript.NodeJS.HttpNodeJSService[0]
      Starting FileWatcher. Current process: 106004.
info: Jering.Javascript.NodeJS.HttpNodeJSService[0]
      Killing NodeJS process: 85688.
info: System.Net.Http.HttpClient.IHttpClientService.LogicalHandler[100]
      Start processing HTTP request POST http://[::1]:55804/
info: System.Net.Http.HttpClient.IHttpClientService.ClientHandler[100]
      Sending HTTP request POST http://[::1]:55804/
info: System.Net.Http.HttpClient.IHttpClientService.ClientHandler[101]
      Received HTTP response headers after 17.3845ms - 200
info: System.Net.Http.HttpClient.IHttpClientService.LogicalHandler[101]
      End processing HTTP request after 17.4303ms - 200

I suspect there is an orphan node process somewhere?

I have configured concurrency, not sure if that could be the reason?

builder.Services.Configure<OutOfProcessNodeJSServiceOptions>(options =>
{
    options.Concurrency = Concurrency.MultiProcess;
    options.InvocationTimeoutMS = -1;
});

I am using .NET 8, Node 20 and version 7.0.0-beta.4 of the library due to another issue here: #186

@CallumVass
Copy link
Author

Implemented my own hosted node service, closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant