-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
running netcoreapp3.1 under win x64.
see https://github.com/coderb/DotnetCore31TimeoutBug
i've isolated a case where HttpWebRequest hangs and does not timeout properly even though Timeout is set.
in this particular case i am tunneling SSL through a proxy (via CONNECT) and the proxy server accepts the connection, completes the SSL handshake, returns the response http headers (but does not include the Content-Length header) and then hangs.
in most other cases the client times out properly (eg if the server hangs prior to ssl handshake or if the server does return the Content-Length header.)
i found this while investigating what i thought were hangs due to ReadWriteTimeout being unsupported #21845 #28404 ( @stephentoub please hear my call ) but this seems to be a distinct bug.
i would recommend auditing the code involved in the handling of timeouts when ssl and or a proxy is used because it seems to be a potentially lesser tested code path.
here's the stack on the client when it is not timing out:
[Managed to Native Transition]
System.Net.Sockets.dll!System.Net.Sockets.SocketPal.Receive(System.Net.Sockets.SafeSocketHandle handle, System.Span<byte> buffer, System.Net.Sockets.SocketFlags socketFlags, out int bytesTransferred) Unknown
System.Net.Sockets.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) Unknown
System.Net.Sockets.dll!System.Net.Sockets.NetworkStream.Read(byte[] buffer, int offset, int size) Unknown
System.Net.Http.dll!System.Net.Http.HttpConnection.ReadBuffered(System.Span<byte> destination) Unknown
System.Net.Http.dll!System.Net.Http.HttpConnection.RawConnectionStream.Read(System.Span<byte> buffer) Unknown
System.Net.Http.dll!System.Net.Http.HttpBaseStream.Read(byte[] buffer, int offset, int count) Unknown
System.Net.Security.dll!System.Net.Security.SslStream.FillBufferAsync<System.Net.Security.SslStream.SslReadSync>(System.Net.Security.SslStream.SslReadSync adapter, int minSize) Unknown
System.Net.Security.dll!System.Net.Security.SslStream.ReadAsyncInternal<System.Net.Security.SslStream.SslReadSync>(System.Net.Security.SslStream.SslReadSync adapter, System.Memory<byte> buffer) Unknown
System.Net.Security.dll!System.Net.Security.SslStream.Read(byte[] buffer, int offset, int count) Unknown
System.Private.CoreLib.dll!System.IO.Stream.Read(System.Span<byte> buffer) Unknown
System.Net.Http.dll!System.Net.Http.HttpConnection.Read(System.Span<byte> destination) Unknown
System.Net.Http.dll!System.Net.Http.HttpConnection.ConnectionCloseReadStream.Read(System.Span<byte> buffer) Unknown
> BugClient.dll!ConsoleApp1.Program.ReadToMemoryStream(System.IO.Stream stream) Line 33 C#
BugClient.dll!ConsoleApp1.Program.Run() Line 22 C#
BugClient.dll!ConsoleApp1.Program.Main(string[] args) Line 13 C#
and another stack i captured somewhere else (no repro)
[Managed to Native Transition]
System.Net.Sockets.dll!System.Net.Sockets.SocketPal.Receive(System.Net.Sockets.SafeSocketHandle handle, System.Span<byte> buffer, System.Net.Sockets.SocketFlags socketFlags, out int bytesTransferred) Unknown
System.Net.Sockets.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) Unknown
System.Net.Sockets.dll!System.Net.Sockets.NetworkStream.Read(byte[] buffer, int offset, int size) Unknown
System.Net.Http.dll!System.Net.Http.HttpConnection.ReadBuffered(System.Span<byte> destination) Line 2214 C#
System.Net.Http.dll!System.Net.Http.HttpConnection.RawConnectionStream.Read(System.Span<byte> buffer) Line 848 C#
System.Net.Http.dll!System.Net.Http.HttpBaseStream.Read(byte[] buffer, int offset, int count) Line 107 C#
System.Net.Security.dll!System.Net.Security.SslStream.FillBufferAsync<System.Net.Security.SslStream.SslReadSync>(System.Net.Security.SslStream.SslReadSync adapter, int minSize) Unknown
System.Net.Security.dll!System.Net.Security.SslStream.ReadAsyncInternal<System.Net.Security.SslStream.SslReadSync>(System.Net.Security.SslStream.SslReadSync adapter, System.Memory<byte> buffer) Unknown
System.Net.Security.dll!System.Net.Security.SslStream.Read(byte[] buffer, int offset, int count) Unknown
System.Private.CoreLib.dll!System.IO.Stream.Read(System.Span<byte> buffer) Unknown
System.Net.Http.dll!System.Net.Http.HttpConnection.Read(System.Span<byte> destination) Line 2171 C#
System.Net.Http.dll!System.Net.Http.HttpConnection.ContentLengthReadStream.Read(System.Span<byte> buffer) Line 535 C#
> System.Net.Http.dll!System.Net.Http.HttpBaseStream.Read(byte[] buffer, int offset, int count) Line 107 C#
System.Net.Http.HttpClient System.Net.HttpWebReqeust