From b089ccfa3d351b4dba43bcbc284d87d7c4963dae Mon Sep 17 00:00:00 2001 From: Tedd Hansen Date: Sat, 2 Feb 2008 06:34:07 +0000 Subject: Hopefully fixed MySQL DB crash on startup issue (so we can remove 3 sec wait). Added option to try alternate UDP ports if the one configured is in use. UDP packets are now bound to the actual outside IP address and hopefully won't "randomly" select IP on multihomed systems. --- OpenSim/Framework/Console/LogBase.cs | 14 ++++++- OpenSim/Framework/Data.MySQL/MySQLDataStore.cs | 5 ++- OpenSim/Framework/RegionInfo.cs | 16 +++++++- OpenSim/Framework/SerializableRegionInfo.cs | 2 + .../Region/ClientStack/RegionApplicationBase.cs | 10 ++++- OpenSim/Region/ClientStack/UDPServer.cs | 45 +++++++++++++++++---- bin/OpenSim.32BitLaunch.exe | Bin 4608 -> 4608 bytes bin/OpenSim.32BitLaunch.pdb | Bin 11776 -> 11776 bytes 8 files changed, 78 insertions(+), 14 deletions(-) diff --git a/OpenSim/Framework/Console/LogBase.cs b/OpenSim/Framework/Console/LogBase.cs index 0036921..f7d0d1f 100644 --- a/OpenSim/Framework/Console/LogBase.cs +++ b/OpenSim/Framework/Console/LogBase.cs @@ -67,7 +67,19 @@ namespace OpenSim.Framework.Console System.Console.WriteLine("Logs will be saved to current directory in " + LogFile); - Log = File.AppendText(LogFile); + try + { + Log = File.AppendText(LogFile); + } + catch (Exception ex) + { + System.Console.WriteLine("Unable to open log file. Do you already have another copy of OpenSim running? Permission problem?"); + System.Console.WriteLine(ex.Message); + System.Console.WriteLine(""); + System.Console.WriteLine("Application is terminating."); + System.Console.WriteLine(""); + System.Threading.Thread.CurrentThread.Abort(); + } Log.WriteLine("========================================================================"); Log.WriteLine(componentname + " Started at " + DateTime.Now.ToString()); } diff --git a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs index 7ac4bde..45d0720 100644 --- a/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs +++ b/OpenSim/Framework/Data.MySQL/MySQLDataStore.cs @@ -417,8 +417,9 @@ namespace OpenSim.Framework.Data.MySQL public void StoreLandObject(Land parcel, LLUUID regionUUID) { - MainLog.Instance.Verbose("DATASTORE", "Tedds temp fix: Waiting 3 seconds for stuff to catch up. (Someone please fix! :))"); - System.Threading.Thread.Sleep(3000); + // Does the new locking fix it? + //MainLog.Instance.Verbose("DATASTORE", "Tedds temp fix: Waiting 3 seconds for stuff to catch up. (Someone please fix! :))"); + //System.Threading.Thread.Sleep(3000); lock (DBAccessLock) { diff --git a/OpenSim/Framework/RegionInfo.cs b/OpenSim/Framework/RegionInfo.cs index 8d4e905..b843774 100644 --- a/OpenSim/Framework/RegionInfo.cs +++ b/OpenSim/Framework/RegionInfo.cs @@ -67,6 +67,7 @@ namespace OpenSim.Framework m_internalEndPoint = ConvertFrom.InternalEndPoint; m_externalHostName = ConvertFrom.ExternalHostName; m_remotingPort = ConvertFrom.RemotingPort; + m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports; RemotingAddress = ConvertFrom.RemotingAddress; RegionID = LLUUID.Zero; } @@ -80,6 +81,7 @@ namespace OpenSim.Framework get { return m_remotingPort; } set { m_remotingPort = value; } } + public bool m_allow_alternate_ports; public string RemotingAddress; @@ -125,6 +127,8 @@ namespace OpenSim.Framework set { m_externalHostName = value; } } + protected bool Allow_Alternate_Ports; + protected IPEndPoint m_internalEndPoint; public IPEndPoint InternalEndPoint @@ -163,6 +167,8 @@ namespace OpenSim.Framework public bool isSandbox = false; public bool commFailTF = false; + public bool m_allow_alternate_ports; + public LLUUID MasterAvatarAssignedUUID = LLUUID.Zero; public LLUUID CovenantID = LLUUID.Zero; public string MasterAvatarFirstName = String.Empty; @@ -217,6 +223,7 @@ namespace OpenSim.Framework m_internalEndPoint = ConvertFrom.InternalEndPoint; m_externalHostName = ConvertFrom.ExternalHostName; m_remotingPort = ConvertFrom.RemotingPort; + m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports; RemotingAddress = ConvertFrom.RemotingAddress; RegionID = LLUUID.Zero; } @@ -228,6 +235,7 @@ namespace OpenSim.Framework m_internalEndPoint = ConvertFrom.InternalEndPoint; m_externalHostName = ConvertFrom.ExternalHostName; m_remotingPort = ConvertFrom.RemotingPort; + m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports; RemotingAddress = ConvertFrom.RemotingAddress; RegionID = LLUUID.Zero; } @@ -300,6 +308,9 @@ namespace OpenSim.Framework configMember.addConfigurationOption("internal_ip_port", ConfigurationOption.ConfigurationTypes.TYPE_INT32, "Internal IP Port for incoming UDP client connections", NetworkServersInfo.DefaultHttpListenerPort.ToString(), false); + configMember.addConfigurationOption("allow_alternate_ports", ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN, + "Allow sim to find alternate UDP ports when ports are in use?", + "false", false); configMember.addConfigurationOption("external_host_name", ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, "External Host Name", "127.0.0.1", false); @@ -357,7 +368,10 @@ namespace OpenSim.Framework m_internalEndPoint = new IPEndPoint(address, 0); break; case "internal_ip_port": - m_internalEndPoint.Port = (int) configuration_result; + m_internalEndPoint.Port = (int)configuration_result; + break; + case "allow_alternate_ports": + m_allow_alternate_ports = (bool)configuration_result; break; case "external_host_name": if ((string) configuration_result != "SYSTEMIP") diff --git a/OpenSim/Framework/SerializableRegionInfo.cs b/OpenSim/Framework/SerializableRegionInfo.cs index 18a3829..0097fe4 100644 --- a/OpenSim/Framework/SerializableRegionInfo.cs +++ b/OpenSim/Framework/SerializableRegionInfo.cs @@ -49,6 +49,7 @@ namespace OpenSim.Framework m_internalEndPoint = ConvertFrom.InternalEndPoint; m_externalHostName = ConvertFrom.ExternalHostName; m_remotingPort = ConvertFrom.RemotingPort; + m_allow_alternate_ports = ConvertFrom.m_allow_alternate_ports; RemotingAddress = ConvertFrom.RemotingAddress; } @@ -80,6 +81,7 @@ namespace OpenSim.Framework get { return m_remotingPort; } set { m_remotingPort = value; } } + public bool m_allow_alternate_ports; public string RemotingAddress; diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs index e74873d..f8b0c9e 100644 --- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs +++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs @@ -109,10 +109,16 @@ namespace OpenSim.Region.ClientStack protected Scene SetupScene(RegionInfo regionInfo, out UDPServer udpServer, bool m_permissions) { AgentCircuitManager circuitManager = new AgentCircuitManager(); - udpServer = new UDPServer((uint) regionInfo.InternalEndPoint.Port, m_assetCache, m_log, circuitManager); + IPAddress listenIP; + if (!IPAddress.TryParse(regionInfo.ExternalHostName, out listenIP)) + listenIP = IPAddress.Parse("0.0.0.0"); - Scene scene = CreateScene(regionInfo, m_storageManager, circuitManager); + uint port = (uint) regionInfo.InternalEndPoint.Port; + udpServer = new UDPServer(listenIP, ref port, regionInfo.m_allow_alternate_ports, m_assetCache, m_log, circuitManager); + regionInfo.InternalEndPoint.Port = (int)port; + Scene scene = CreateScene(regionInfo, m_storageManager, circuitManager); + udpServer.LocalScene = scene; scene.LoadWorldMap(); diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs index dc76c20..e292c2c 100644 --- a/OpenSim/Region/ClientStack/UDPServer.cs +++ b/OpenSim/Region/ClientStack/UDPServer.cs @@ -52,6 +52,8 @@ namespace OpenSim.Region.ClientStack protected ulong m_regionHandle; protected uint listenPort; + protected bool Allow_Alternate_Port; + protected IPAddress listenIP = IPAddress.Parse("0.0.0.0"); protected IScene m_localScene; protected AssetCache m_assetCache; protected LogBase m_log; @@ -82,13 +84,20 @@ namespace OpenSim.Region.ClientStack { } - public UDPServer(uint port, AssetCache assetCache, LogBase console, AgentCircuitManager authenticateClass) + public UDPServer(IPAddress _listenIP, ref uint port, bool allow_alternate_port, AssetCache assetCache, LogBase console, AgentCircuitManager authenticateClass) { + listenIP = _listenIP; listenPort = port; + Allow_Alternate_Port = allow_alternate_port; m_assetCache = assetCache; m_log = console; m_authenticateSessionsClass = authenticateClass; CreatePacketServer(); + + // Return new port + // This because in Grid mode it is not really important what port the region listens to as long as it is correctly registered. + // So the option allow_alternate_ports="true" was added to default.xml + port = listenPort; } protected virtual void CreatePacketServer() @@ -98,7 +107,7 @@ namespace OpenSim.Region.ClientStack protected virtual void OnReceivedData(IAsyncResult result) { - ipeSender = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); + ipeSender = new IPEndPoint(listenIP, 0); epSender = (EndPoint) ipeSender; Packet packet = null; @@ -246,20 +255,40 @@ namespace OpenSim.Region.ClientStack public void ServerListener() { - m_log.Verbose("SERVER", "Opening UDP socket on " + listenPort.ToString()); - ServerIncoming = new IPEndPoint(IPAddress.Parse("0.0.0.0"), (int) listenPort); - Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); - Server.Bind(ServerIncoming); + uint newPort = listenPort; + for (uint i = 0; i < 10; i++) + { + newPort = listenPort + i; + m_log.Verbose("SERVER", "Opening UDP socket on " + listenIP.ToString() + " " + newPort + ". Allow alternate ports: " + Allow_Alternate_Port.ToString()); + try + { + ServerIncoming = new IPEndPoint(listenIP, (int) newPort); + Server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + Server.Bind(ServerIncoming); + listenPort = newPort; + break; + } + catch (Exception ex) + { + // We are not looking for alternate ports? + if (!Allow_Alternate_Port) + throw (ex); + + // We are looking for alternate ports! + m_log.Verbose("SERVER", "UDP socket on " + listenIP.ToString() + " " + listenPort.ToString() + " is not available, trying next."); + } + System.Threading.Thread.Sleep(100); // Wait before we retry socket + } m_log.Verbose("SERVER", "UDP socket bound, getting ready to listen"); - ipeSender = new IPEndPoint(IPAddress.Parse("0.0.0.0"), 0); + ipeSender = new IPEndPoint(listenIP, 0); epSender = (EndPoint) ipeSender; ReceivedData = new AsyncCallback(OnReceivedData); Server.BeginReceiveFrom(RecvBuffer, 0, RecvBuffer.Length, SocketFlags.None, ref epSender, ReceivedData, null); - m_log.Status("SERVER", "Listening..."); + m_log.Status("SERVER", "Listening on port " + newPort); } public virtual void RegisterPacketServer(PacketServer server) diff --git a/bin/OpenSim.32BitLaunch.exe b/bin/OpenSim.32BitLaunch.exe index 5a2c715..9a91a62 100644 Binary files a/bin/OpenSim.32BitLaunch.exe and b/bin/OpenSim.32BitLaunch.exe differ diff --git a/bin/OpenSim.32BitLaunch.pdb b/bin/OpenSim.32BitLaunch.pdb index d9ca537..eacf47c 100644 Binary files a/bin/OpenSim.32BitLaunch.pdb and b/bin/OpenSim.32BitLaunch.pdb differ -- cgit v1.1