/** <summary>Closes all resources and fails all pending requests.</summary> */ private void shutdown() { Dbg.Assert(closed); Dbg.Assert(!Thread.CurrentThread.Equals(rdr)); rdr.Interrupt(); writer.Interrupt(); rdr.Join(); writer.Join(); lock (outStream) { // It's unclear from documentation why this call is needed, // but without it we get IOException on the server. U.DoSilent <Exception>(() => tcp.Client.Disconnect(false), null); U.DoSilent <Exception>(() => outStream.Close(), null); U.DoSilent <Exception>(() => tcp.Close(), null); } foreach (GridClientFuture fut in pendingReqs.Values) { fut.Fail(() => { throw new GridClientClosedException("Failed to perform request" + " (connection was closed before response was received): " + ServerAddress); }); } Dbg.WriteLine("Connection closed: " + ServerAddress); }