Dns Server with UDP/TCP

Jul 30, 2014 at 10:07 AM
Edited Jul 30, 2014 at 10:08 AM
Hello SuperSocket Team

I am write on a Dns Server with SuperSocket 1.6.2.1. It runs good, process 100 requests per second. But about a day it stops sending answers. Receiving works after stopped. In the log file write this error permanently. I also try directly from the Server nslookup test.de 127.0.0.1 with the same effect, no response.
System.TimeoutException: The sending attempt timed out
   at SuperSocket.SocketBase.AppSession`2.InternalSend(ArraySegment`1 segment)
   at SuperSocket.SocketBase.AppSession`2.Send(Byte[] data, Int32 offset, Int32 length)
   at company.DnsServerCore.NewRequestReceived(DnsSession session, BinaryRequestInfo requestInfo)
I think the config is maybee not perfect but i can not found a best practices for a udp config.

UDP Config
            #region Configuration
            var configUdp = new SuperSocket.SocketBase.Config.ServerConfig();
            configUdp.Mode = SocketMode.Udp;
            configUdp.Port = 53;
            configUdp.MaxConnectionNumber = 200;
            configUdp.ClearIdleSession = true;
            configUdp.ClearIdleSessionInterval = 60; //The clearing timeout idle session interval (seconds)
            configUdp.IdleSessionTimeOut = 10;
            configUdp.MaxRequestLength = 500;
            configUdp.ListenBacklog = 100; //Waiting Connection Pool
            configUdp.SendBufferSize = 512;
            configUdp.ReceiveBufferSize = 512;
            configUdp.SyncSend = true;
            configUdp.SendTimeOut = 5;
            configUdp.LogBasicSessionActivity = false;
            #endregion
TCP Config
            #region Configuration
            var configTcp = new SuperSocket.SocketBase.Config.ServerConfig();
            configTcp.Mode = SocketMode.Tcp;
            configTcp.Port = 53;
            configTcp.MaxConnectionNumber = 20;
            configTcp.ClearIdleSession = true;
            configTcp.ClearIdleSessionInterval = 60; //The clearing timeout idle session interval (seconds)
            configTcp.IdleSessionTimeOut = 10;
            configTcp.MaxRequestLength = 500;
            configTcp.ListenBacklog = 100; //Waiting Connection Pool
            configTcp.SendBufferSize = 512;
            configTcp.ReceiveBufferSize = 512;
            configTcp.SyncSend = true;
            configTcp.SendTimeOut = 5;
            configTcp.LogBasicSessionActivity = false;
            #endregion
If advantageous to change to TrySend?
private void NewRequestReceived(DnsSession session, BinaryRequestInfo requestInfo)
        {
            Interlocked.Increment(ref this._totalRequestCount);

            try
            {
                var query = DnsMessage.Parse(requestInfo.Body);
                query.IsQuery = false;

                var answer = this.ProcessQuery(query);
                byte[] data;
                if (session.Config.Mode == SocketMode.Udp)
                {
                    data = query.Encode(false);
                }
                else
                {
                    data = query.Encode(true);
                }

                session.Send(data, 0, data.Length);
            }
            catch (TimeoutException exception)
            {
                Interlocked.Increment(ref this._totalErrorCount);
                Log.Error("NewRequestReceived", exception);
            }
            catch (Exception exception)
            {
                Interlocked.Increment(ref this._totalErrorCount);
                var sb = new StringBuilder();
                foreach (var b in requestInfo.Body)
                {
                    sb.AppendFormat("{0} ", b);
                }

                Log.Error(String.Format("NewRequestReceived - Bytes:{0}", sb.ToString()), exception);
            }
            session.Close();
        }
Coordinator
Jul 31, 2014 at 2:32 PM
Yes, you can enlarge the configTcp.SendingQueueSize to relieve this issue.
Sep 9, 2014 at 7:56 AM
Edited Sep 9, 2014 at 7:57 AM
I monitor the udp server for a longer time and now i have a permanent udp session open over 7 days with a last active time 1 day ago. In the log file i have see
The session will be closed for 93435,6465111 timeout, the session start time: 02.09.2014 20:16:21, last active time: 08.09.2014 07:55:08!
but the session is allways open.
Sep 17, 2014 at 8:23 AM
Edited Sep 17, 2014 at 8:25 AM
I start a other test with disabled syncsend, now i have much more hanging sessions. For me is strange udp have no permanent connections and anyway i have a session list...

If additional informations required please response.
Sep 20, 2014 at 5:22 PM
The Dns Server stopped with the following error

Application: DnsSocket.Service.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
Stack:
at SuperSocket.SocketEngine.SocketSession.OnSendEnd(Boolean)
at SuperSocket.SocketEngine.SocketSession.OnSendingCompleted(SuperSocket.Common.SendingQueue)
at SuperSocket.SocketEngine.UdpSocketSession.OnSendingCompleted(System.Object, System.Net.Sockets.SocketAsyncEventArgs)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(System.Net.Sockets.SocketError, Int32, System.Net.Sockets.SocketFlags)
at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
Coordinator
Sep 20, 2014 at 5:48 PM
Could you upgrade to the latest version of SuperSocket at first?
Sep 22, 2014 at 8:24 AM
okay i upgrade to Version "1.6.3". I have also test to upgrade to the current build on github but i miss "BinaryRequestInfo" in SuperSocket.SocketBase.Protocol...
Sep 25, 2014 at 12:54 PM
With Version 1.6.3

Application: DnsSocket.Service.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
Stack:
at SuperSocket.SocketEngine.SocketSession.OnSendingCompleted(SuperSocket.Common.SendingQueue)
at SuperSocket.SocketEngine.UdpSocketSession.OnSendingCompleted(System.Object, System.Net.Sockets.SocketAsyncEventArgs)
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs)
at System.Net.Sockets.SocketAsyncEventArgs.ExecutionCallback(System.Object)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(System.Net.Sockets.SocketError, Int32, System.Net.Sockets.SocketFlags)
at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
Sep 25, 2014 at 5:34 PM
With Version 1.6.3

Application: DnsSocket.Service.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
Stack:
at SuperSocket.SocketEngine.SocketSession.OnSendEnd(Boolean)
at SuperSocket.SocketEngine.SocketSession.OnSendingCompleted(SuperSocket.Common.SendingQueue)
at SuperSocket.SocketEngine.UdpSocketSession.OnSendingCompleted(System.Object, System.Net.Sockets.SocketAsyncEventArgs)
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs)
at System.Net.Sockets.SocketAsyncEventArgs.ExecutionCallback(System.Object)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(System.Net.Sockets.SocketError, Int32, System.Net.Sockets.SocketFlags)
at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32, UInt32, System.Threading.NativeOverlapped*)
Coordinator
Sep 25, 2014 at 5:37 PM
Ok, I'll check this issue tonight.
Coordinator
Sep 26, 2014 at 6:10 AM
Sep 26, 2014 at 2:33 PM
Okay thanks. I have changed to 1.6.4. I am give a report next week.
Sep 30, 2014 at 4:01 PM
i have check today the sessions and i have no open sessions. At the moment it looks very good... I report the next days again...
Oct 6, 2014 at 7:15 AM
Edited Oct 6, 2014 at 8:08 AM
After 50 million requests the udp server stop again. I check the log files for errors and can found following.
I create a test project for reproduce the error but on my test project after 350 million requests its run perfectly.
Maybe corrupt udp packages generate the error?
02:22:20,669 [653] ERROR DnsServerUdp-41560081 - Session: 218.201.21.138:28258/218.201.21.138:28258
The session is refused because the it's ID already exists!
02:22:20,669 [644] ERROR DnsServerUdp-41560081 - Session: 218.201.21.138:28258/218.201.21.138:28258
The session is refused because the it's ID already exists!
also lines with not closed sessions
2014-10-06 06:49:38,982 [100] INFO  DnsServerUdp-62676156 - Session: 192.155.84.126:43977/192.155.84.126:43977
The session will be closed for 45875,0161752 timeout, the session start time: 05.10.2014 11:13:07, last active time: 05.10.2014 18:05:03!
2014-10-06 09:09:40,876 [97] INFO  DnsServerUdp-62676156 - Session: 192.155.84.126:43977/192.155.84.126:43977
The session will be closed for 54276,9101324 timeout, the session start time: 05.10.2014 11:13:07, last active time: 05.10.2014 18:05:03!
and the sending Problem
23:37:10,248 [1068] ERROR DnsSocket.Library.Core.DnsServerCore - NewRequestReceived
System.TimeoutException: The sending attempt timed out
   at SuperSocket.SocketBase.AppSession`2.InternalSend(ArraySegment`1 segment)
   at SuperSocket.SocketBase.AppSession`2.Send(Byte[] data, Int32 offset, Int32 length)
   at adRom.DnsSocket.Library.Core.DnsServerCore.NewRequestReceived(DnsSession session, BinaryRequestInfo requestInfo)
23:37:10,248 [1110] ERROR DnsSocket.Library.Core.DnsServerCore - NewRequestReceived
System.TimeoutException: The sending attempt timed out
   at SuperSocket.SocketBase.AppSession`2.InternalSend(ArraySegment`1 segment)
   at SuperSocket.SocketBase.AppSession`2.Send(Byte[] data, Int32 offset, Int32 length)
Oct 6, 2014 at 8:05 AM
Edited Oct 6, 2014 at 8:06 AM
i have install wireshark on the Server and capture the traffic now, maybe i can found a bad udp package
Oct 20, 2014 at 12:19 PM
The Service run now for 2 weeks and now it beginns with the following Errors...
I have captured the traffic and try now to repeat to my visual studio.
11:57:48,765 [727] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
11:57:48,765 [727] INFO  DnsServerUdp-41560081 - Session: 81.169.144.248:50832/81.169.144.248:50832
This session was closed for InternalError!
14:19:04,416 [715] ERROR adRom.DnsSocket.Library.Core.DnsServerCore - NewRequestReceived
System.TimeoutException: The sending attempt timed out
   at SuperSocket.SocketBase.AppSession`2.InternalSend(ArraySegment`1 segment)
   at SuperSocket.SocketBase.AppSession`2.Send(Byte[] data, Int32 offset, Int32 length)
   at adRom.DnsSocket.Library.Core.DnsServerCore.NewRequestReceived(DnsSession session, BinaryRequestInfo requestInfo)
14:19:04,416 [735] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,416 [715] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,432 [715] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,432 [715] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,463 [712] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,463 [743] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,229 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,635 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,635 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,635 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,837 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,837 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,837 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,837 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,837 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,837 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,837 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,853 [718] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,416 [735] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:04,635 [715] ERROR DnsServerUdp-41560081 - There is no enougth sending queue can be used.
14:19:05,025 [711] ERROR adRom.DnsSocket.Library.Core.DnsServerCore - NewRequestReceived
System.TimeoutException: The sending attempt timed out
   at SuperSocket.SocketBase.AppSession`2.InternalSend(ArraySegment`1 segment)
   at SuperSocket.SocketBase.AppSession`2.Send(Byte[] data, Int32 offset, Int32 length)