-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Description
I've noticed that non-GET requests in HttpClient will fail with HttpRequestException if remote server closes pooled connection.
Steps to Reproduce
-
Prepare an HTTP server that uses Keep-Alive but has small idle timeout (1 second).
- For example, use
run_nginx.shscript from
https://gist.github.com/dmitryvk/2bf190d41267b242ed8ca31f63ea40e0#file-run_nginx-sh. This script will run minimal nginx server which has Keep-Alive idle timeout set to 1 second (notekeepalive_timeout 1;in nginx_template.conf).
- For example, use
-
Compile and run the following program: https://gist.github.com/dmitryvk/2bf190d41267b242ed8ca31f63ea40e0#file-program-cs
Current Behavior
Programs outputs:
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>
System.AggregateException: One or more errors occurred. (An error occurred while sending the request.) ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: The server returned an invalid or unrecognized response.
at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00cf5] in <f060cf3977d54c358d58805336bde9d1>:0
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x012e5] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync (System.Net.Http.HttpConnection connection, System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0012b] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync (System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0014b] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.RedirectHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000ba] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in <f060cf3977d54c358d58805336bde9d1>:0
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in <6ea21d94575948579c2890f43ad5bec5>:0
at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in <6ea21d94575948579c2890f43ad5bec5>:0
at System.Threading.Tasks.Task`1[TResult].get_Result () [0x0000f] in <6ea21d94575948579c2890f43ad5bec5>:0
at HttpClientTest.Program.Main (System.String[] args) [0x0005c] in <d73b3300d48b402092ac95202adc3c1c>:0
---> (Inner Exception #0) System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: The server returned an invalid or unrecognized response.
at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00cf5] in <f060cf3977d54c358d58805336bde9d1>:0
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x012e5] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync (System.Net.Http.HttpConnection connection, System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0012b] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync (System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0014b] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.RedirectHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000ba] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in <f060cf3977d54c358d58805336bde9d1>:0 <---
Expected Behavior
Program should output (as it does when run in .NET Core):
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.12.1</center>
</body>
</html>
On which platforms did you notice this
[ ] macOS
[x] Linux
[ ] Windows
Version Used:
Mono JIT compiler version 6.4.0.198 (tarball Mon Sep 23 20:53:41 UTC 2019)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
Interpreter: yes
LLVM: yes(610)
Suspend: hybrid
GC: sgen (concurrent by default)
Stacktrace
System.AggregateException: One or more errors occurred. (An error occurred while sending the request.) ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: The server returned an invalid or unrecognized response.
at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00cf5] in <f060cf3977d54c358d58805336bde9d1>:0
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x012e5] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync (System.Net.Http.HttpConnection connection, System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0012b] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync (System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0014b] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.RedirectHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000ba] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in <f060cf3977d54c358d58805336bde9d1>:0
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in <6ea21d94575948579c2890f43ad5bec5>:0
at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in <6ea21d94575948579c2890f43ad5bec5>:0
at System.Threading.Tasks.Task`1[TResult].get_Result () [0x0000f] in <6ea21d94575948579c2890f43ad5bec5>:0
at HttpClientTest.Program.Main (System.String[] args) [0x0005c] in <d73b3300d48b402092ac95202adc3c1c>:0
---> (Inner Exception #0) System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: The server returned an invalid or unrecognized response.
at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00cf5] in <f060cf3977d54c358d58805336bde9d1>:0
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnection.SendAsyncCore (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x012e5] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync (System.Net.Http.HttpConnection connection, System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0012b] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync (System.Net.Http.HttpRequestMessage request, System.Boolean doRequestAuth, System.Threading.CancellationToken cancellationToken) [0x0014b] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.RedirectHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x000ba] in <f060cf3977d54c358d58805336bde9d1>:0
at System.Net.Http.HttpClient.FinishSendAsyncBuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x0017e] in <f060cf3977d54c358d58805336bde9d1>:0 <---