microsoft / dotnet

This repo is the official home of .NET on GitHub. It's a great starting point to find many .NET OSS projects from Microsoft and the community, including many that are part of the .NET Foundation.
https://devblogs.microsoft.com/dotnet/
MIT License
14.25k stars 2.2k forks source link

macos 14.1 HttpClient Error: System.IO.IOException: Unable to write data to the transport connection: Broken pipe #1412

Open ty793941 opened 8 months ago

ty793941 commented 8 months ago

operating system: macos 14.1 sonama dotnet : 7.0.2

Error Code:

HttpClient httpClient = new HttpClient();
try
{
    var s = httpClient.GetAsync("http://www.baidu.com").Result;
}
catch (Exception ex)
{
    Console.WriteLine(ex.ToString());
}

The Exception:

   at System.Threading.Tasks.Task.RunContinuations(Object continuationObject)
   at System.Threading.Tasks.Task`1.TrySetResult(TResult result)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetExistingTaskResult(Task`1 task, TResult result)
   at System.Net.Http.HttpConnectionPool.HttpConnectionWaiter`1.WaitForConnectionAsync(Boolean async, CancellationToken requestCancellationToken)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext()
   at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox box, Boolean allowInlining)
   at System.Threading.Tasks.Task.RunContinuations(Object continuationObject)
   at System.Threading.Tasks.Task`1.TrySetResult(TResult result)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetExistingTaskResult(Task`1 task, TResult result)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecutionContextCallback(Object s)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.MoveNext(Thread threadPoolThread)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.AsyncStateMachineBox`1.ExecuteFromThreadPool(Thread threadPoolThread)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()
--- End of stack trace from previous location ---

When I haven't upgraded to macos 14.1,everything is ok,But when I upgraded to macos 14.1, all the HttpClient is error with the same exception 。

I create the new project,it‘s the same exception。

Please help me!

image
ty793941 commented 8 months ago

i found two:

  1. I has used the VPN,influenced me。Then close VPN:

    //it's working.
    var s = await httpClient.GetAsync("http://www.baidu.com");
    
    //it's working.
    var s1 = httpClient.GetAsync("http://localhost:8001/home/getenv").Result;
    
    //it's report the exception
    var s1 = httpClient.GetAsync("http://127.0.0.1:8001/home/getenv").Result;
  2. Based on the above,I found the "localhost:8001" is ok, and the "127.0.0.1:8001" is not work.

And it maybe not the dotnet issue.