From 46cac455c12bbf2ee2bc9ecb499cb1367ad920c9 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Wed, 14 Jan 2009 20:40:14 +0000 Subject: * Move the timed_out change to earlier on in the async handler * There appears to be a bug on mono 1.9.1 (and maybe later), where sometimes the async wait will be signalled even though that async callback has not executed * This change may make it slightly better but it's difficult to tell (it definitely still occurs) * Also this patch closes the wait handle explicitly, as recommended in the MSDN docs. This doesn't have any impact on the bug though --- OpenSim/Region/Communications/OGS1/OGS1GridServices.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs index 64e184d..ca48814 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs @@ -1567,12 +1567,13 @@ namespace OpenSim.Region.Communications.OGS1 AsyncCallback callback = delegate(IAsyncResult iar) { + timed_out = false; + Socket s = (Socket)iar.AsyncState; try { s.EndConnect(iar); - available = true; - timed_out = false; + available = true; } catch (Exception e) { @@ -1583,10 +1584,12 @@ namespace OpenSim.Region.Communications.OGS1 s.Close(); }; + IAsyncResult ar; + try { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - IAsyncResult ar = socket.BeginConnect(m_EndPoint, callback, socket); + ar = socket.BeginConnect(m_EndPoint, callback, socket); ar.AsyncWaitHandle.WaitOne(timeOut * 1000, false); } catch (Exception e) @@ -1596,9 +1599,11 @@ namespace OpenSim.Region.Communications.OGS1 return false; } + + ar.AsyncWaitHandle.Close(); if (timed_out) - { + { m_log.DebugFormat( "[OGS1 GRID SERVICES]: socket [{0}] timed out ({1}) waiting to obtain a connection.", m_EndPoint, timeOut * 1000); -- cgit v1.1