Fix if already send error to http client, do not callback. (#19668)
commit075c3f06197e3b969f4234d0f56a2e10ee6ee305
authormonojenkins <jo.shields+jenkins@xamarin.com>
Tue, 28 Apr 2020 18:22:51 +0000 (28 14:22 -0400)
committerGitHub <noreply@github.com>
Tue, 28 Apr 2020 18:22:51 +0000 (28 20:22 +0200)
tree33f7bcc549fe580496b00a44e0a8570574e8ae70
parent35cc82cc6cc5430b3e33695ec4a43948b63b3471
Fix if already send error to http client, do not callback. (#19668)

Fixed #10435

HttpListener already closes the Response object, closes the HTTP Client connection, and then sets the value of Response.StatusCode again. If so, an ObjectDisposedException is thrown.

```
Unhandled Exception:
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.HttpListenerResponse'.
  at System.Net.HttpListenerResponse.set_ContentLength64 (System.Int64 value) [0x00013] in <b4473693dd3c4d45883c574a53529fbe>:0
  at MonoConsoleApp1.Program.Main (System.String[] args) [0x000f8] in <a66f6d7d417445dc9f89c691941ca70b>:0
  at MonoConsoleApp1.Program.<Main> (System.String[] args) [0x0000c] in <a66f6d7d417445dc9f89c691941ca70b>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.HttpListenerResponse'.
  at System.Net.HttpListenerResponse.set_ContentLength64 (System.Int64 value) [0x00013] in <b4473693dd3c4d45883c574a53529fbe>:0
  at MonoConsoleApp1.Program.Main (System.String[] args) [0x000f8] in <a66f6d7d417445dc9f89c691941ca70b>:0
  at MonoConsoleApp1.Program.<Main> (System.String[] args) [0x0000c] in <a66f6d7d417445dc9f89c691941ca70b>:0
```

If an error is sent to the HTTP client while processing a request, it is patched so that the next process is not executed anymore.

Backport of #19664.
mcs/class/System/System.Net/HttpConnection.cs
mcs/class/System/System.Net/HttpListenerRequest.cs