.net core для API конечных точек System.Net.Sockets.Исключение SocketException: Ресурс временно недоступен

#c# #node.js #.net #multithreading #raspberry-pi

Вопрос:

У меня проблема с HTTP-запросом, инициированным из программы C#, размещенной на raspberry Pi, подключенной к Интернету с помощью 4G-блока. HTTP-запросы отправляются в API NodeJS, развернутый docker, и доступны через обратный прокси-сервер. Несколько запросов отправляются с регулярными интервалами, однако следующая ошибка завершает программу после нескольких обменов:

  System.Net.Http.HttpRequestException: Resource temporarily unavailable ---> System.Net.Sockets.SocketException: Resource temporarily unavailable
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    --- End of inner exception stack trace ---
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.Tasks.ValueTask`1.get_Result()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.Tasks.ValueTask`1.get_Result()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.Tasks.ValueTask`1.get_Result()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
sept. 21 15:25:15 raspberrypi [15749]:    at Common.WebApi.SendHttpPost(String url, StringContent data)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__7_1(Object state)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.QueueUserWorkItemCallbackDefaultContext.<>c.<.cctor>b__5_0(Object state)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
sept. 21 15:25:15 raspberrypi [15749]: --- End of stack trace from previous location where exception was thrown ---
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.QueueUserWorkItemCallbackDefaultContext.ExecuteWorkItem()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.ThreadPoolWorkQueue.Dispatch()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()System.Net.Http.HttpRequestException: Resource temporarily unavailable ---> System.Net.Sockets.SocketException: Resource temp
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    --- End of inner exception stack trace ---
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.Tasks.ValueTask`1.get_Result()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.Tasks.ValueTask`1.get_Result()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.Tasks.ValueTask`1.get_Result()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
sept. 21 15:25:15 raspberrypi [15749]:    at Common.WebApi.SendHttpPost(String url, StringContent data)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__7_1(Object state)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.QueueUserWorkItemCallbackDefaultContext.<>c.<.cctor>b__5_0(Object state)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
sept. 21 15:25:15 raspberrypi [15749]: --- End of stack trace from previous location where exception was thrown ---
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.QueueUserWorkItemCallbackDefaultContext.ExecuteWorkItem()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.ThreadPoolWorkQueue.Dispatch()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
sept. 21 15:25:15 raspberrypi [15749]: System.Net.Http.HttpRequestException: Resource temporarily unavailable ---> System.Net.Sockets.SocketException: Resource temporarily unavailable
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    --- End of inner exception stack trace ---
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.Tasks.ValueTask`1.get_Result()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.Tasks.ValueTask`1.get_Result()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.Tasks.ValueTask`1.get_Result()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
sept. 21 15:25:15 raspberrypi [15749]:    at Common.WebApi.SendHttpPost(String url, StringContent data)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__7_1(Object state)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.QueueUserWorkItemCallbackDefaultContext.<>c.<.cctor>b__5_0(Object state)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
sept. 21 15:25:15 raspberrypi [15749]: --- End of stack trace from previous location where exception was thrown ---
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.QueueUserWorkItemCallbackDefaultContext.ExecuteWorkItem()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading.ThreadPoolWorkQueue.Dispatch()
sept. 21 15:25:15 raspberrypi [15749]:    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
 

Эта ошибка возникает в любое время, и я не могу ее поймать