Skip to content

HttpWebRequest.ReadWriteTimeout is ignored - reading never times out #28404

@emz00

Description

@emz00

.NET Core 2.1.7 on Windows 7 x64

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://mirror.zetup.net/ubuntu-cd/18.04.1/ubuntu-18.04.1-desktop-amd64.iso");
httpWebRequest.Timeout = 2000;
httpWebRequest.ReadWriteTimeout = 1;

var webResponse = httpWebRequest.GetResponse();
var responseStream = webResponse.GetResponseStream();

int totalBytes = 0, readBytes;
do
{
    var buffer = new byte[16384];
    readBytes = responseStream.Read(buffer, 0, buffer.Length);
    totalBytes += readBytes;
} while (readBytes != 0);

Based on the docs I would expect the responseStream.Read() call to time out, but it never does. responseStream.CanTimeout returns false - so at least it's honest!

In this case the entire file (1953349632 bytes) is eventually downloaded, but in a production case we have the server has not closed the connection for nearly a month now and the client (.NET Core 2.0) is still trying to read from it!

Metadata

Metadata

Assignees

Labels

area-System.NetdocumentationDocumentation bug or enhancement, does not impact product or test code

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions