* 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
0.6.2-post-fixes
Justin Clarke Casey 2009-01-14 20:40:14 +00:00
parent 8a08e4980d
commit 46cac455c1
1 changed files with 9 additions and 4 deletions

View File

@ -1567,12 +1567,13 @@ namespace OpenSim.Region.Communications.OGS1
AsyncCallback callback = delegate(IAsyncResult iar) AsyncCallback callback = delegate(IAsyncResult iar)
{ {
timed_out = false;
Socket s = (Socket)iar.AsyncState; Socket s = (Socket)iar.AsyncState;
try try
{ {
s.EndConnect(iar); s.EndConnect(iar);
available = true; available = true;
timed_out = false;
} }
catch (Exception e) catch (Exception e)
{ {
@ -1583,10 +1584,12 @@ namespace OpenSim.Region.Communications.OGS1
s.Close(); s.Close();
}; };
IAsyncResult ar;
try try
{ {
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 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); ar.AsyncWaitHandle.WaitOne(timeOut * 1000, false);
} }
catch (Exception e) catch (Exception e)
@ -1596,9 +1599,11 @@ namespace OpenSim.Region.Communications.OGS1
return false; return false;
} }
ar.AsyncWaitHandle.Close();
if (timed_out) if (timed_out)
{ {
m_log.DebugFormat( m_log.DebugFormat(
"[OGS1 GRID SERVICES]: socket [{0}] timed out ({1}) waiting to obtain a connection.", "[OGS1 GRID SERVICES]: socket [{0}] timed out ({1}) waiting to obtain a connection.",
m_EndPoint, timeOut * 1000); m_EndPoint, timeOut * 1000);