diff --git a/mcs/class/System/System.Net/WebConnection.cs b/mcs/class/System/System.Net/WebConnection.cs index 551a961572ee..b154e0ff5ca7 100644 --- a/mcs/class/System/System.Net/WebConnection.cs +++ b/mcs/class/System/System.Net/WebConnection.cs @@ -63,6 +63,7 @@ class WebConnection { ServicePoint sPoint; Stream nstream; + IAsyncResult currentNStreamReadAsyncResult; internal Socket socket; object socketLock = new object (); IWebConnectionState state; @@ -505,6 +506,9 @@ void ReadDone (IAsyncResult result) { WebConnectionData data = Data; Stream ns = nstream; + if (currentNStreamReadAsyncResult != result) + return; + if (ns == null) { Close (true); return; @@ -637,7 +641,7 @@ internal void InitRead () try { int size = buffer.Length - position; - ns.BeginRead (buffer, position, size, ReadDone, null); + currentNStreamReadAsyncResult = ns.BeginRead (buffer, position, size, ReadDone, null); } catch (Exception e) { HandleError (WebExceptionStatus.ReceiveFailure, e, "InitRead"); } @@ -1188,6 +1192,7 @@ internal void Close (bool sendNext) try { nstream.Close (); } catch {} + currentNStreamReadAsyncResult = null; nstream = null; }