Page 1 of 1

SMPP Server An exception was thrown by a TaskScheduler. ---> System.OutOfMemoryException:

Posted: Sat Jun 20, 2020 5:52 pm
by ahmedreza
Out of Memory Exception when a clients attempts multiple binds to the server.

19.06.2020 12:10:12:INFO :2920: (SmppServerClient2817.Socket) XXXX:2465 => XXX:61928 Connection established.
19.06.2020 12:10:12:INFO :2920: (SmppServer1) [XXX:61928] connected.
19.06.2020 12:10:12:ERROR:2920: (SmppServerClient2817) Event evConnected failed
Exception: System.Threading.Tasks.TaskSchedulerException: An exception was thrown by a TaskScheduler. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Threading.Thread.StartInternal(IPrincipal principal, StackCrawlMark& stackMark)
at System.Threading.Thread.Start(StackCrawlMark& stackMark)
at System.Threading.Thread.Start(Object parameter)
at System.Threading.Tasks.ThreadPoolTaskScheduler.QueueTask(Task task)
at System.Threading.Tasks.Task.ScheduleAndStart(Boolean needsProtection)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ScheduleAndStart(Boolean needsProtection)
at System.Threading.Tasks.Task.InternalStartNew(Task creatingTask, Delegate action, Object state, CancellationToken cancellationToken, TaskScheduler scheduler, TaskCreationOptions options, InternalTaskOptions internalOptions, StackCrawlMark& stackMark)
at System.Threading.Tasks.TaskFactory.StartNew(Action action, TaskCreationOptions creationOptions)
at Inetlab.SMPP.Common.TimeLimitedQueue..ctor(Int32 capacity)
at Inetlab.SMPP.Common.RateGate.set_Rate(LimitRate value)
at SMPP_Server.frmServer.server_evClientConnected(Object sender, SmppServerClient client)
at Inetlab.SMPP.SmppServer.RaiseClientConnected(SmppServerClient client)
at Inetlab.SMPP.SmppServer.client_evConnected(Object sender, Boolean success)
at Inetlab.SMPP.SmppClientBase.OnConnected(Boolean success)
19.06.2020 12:10:12:ERROR:2920: (SmppServerClient2817.Socket) Event evConnected failed.
Exception: System.Threading.Tasks.TaskSchedulerException: An exception was thrown by a TaskScheduler. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Threading.Thread.StartInternal(IPrincipal principal, StackCrawlMark& stackMark)
at System.Threading.Thread.Start(StackCrawlMark& stackMark)
at System.Threading.Thread.Start(Object parameter)
at System.Threading.Tasks.ThreadPoolTaskScheduler.QueueTask(Task task)
at System.Threading.Tasks.Task.ScheduleAndStart(Boolean needsProtection)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ScheduleAndStart(Boolean needsProtection)
at System.Threading.Tasks.Task.InternalStartNew(Task creatingTask, Delegate action, Object state, CancellationToken cancellationToken, TaskScheduler scheduler, TaskCreationOptions options, InternalTaskOptions internalOptions, StackCrawlMark& stackMark)
at System.Threading.Tasks.TaskFactory.StartNew(Action action, TaskCreationOptions creationOptions)
at Inetlab.SMPP.Common.SmppSocket.StartReading()
at Inetlab.SMPP.Common.SmppSocket.OnConnected()

Re: SMPP Server An exception was thrown by a TaskScheduler. ---> System.OutOfMemoryException:

Posted: Mon Jun 22, 2020 9:23 pm
by alt
Could you provide more details on your context?
What library version do you use?
How many concurrent connections your server accepts?

Consider to create memory dump with ProcDump.

Code: Select all

procdump -ma -e 1 -f OutOfMemoryException -w "YourProcessName"
Once you have a dump file, use DebugDiag to analyze it.

Re: SMPP Server An exception was thrown by a TaskScheduler. ---> System.OutOfMemoryException:

Posted: Tue Jun 23, 2020 10:37 am
by ahmedreza
We have this in bind section to limit 2 connections.

Library Version: ## [2.7.0] - 2019-12-11

//deny multiple connection with same smpp system id max 2 allowed
if (_server.ConnectedClients.Count(c => c.SystemID == data.SystemId) > 2)
{
data.Response.Header.Status = CommandStatus.ESME_RALYBND;

Re: SMPP Server An exception was thrown by a TaskScheduler. ---> System.OutOfMemoryException:

Posted: Sat Jun 27, 2020 9:07 am
by alt
I suppose the client establishes new connection after receiving the response with status ESME_RALYBND, but doesn't disconnect previous connection. When it happens too often you get out of memory exception.

Could you tell me how many maximal connections your server had? It should be a lot of connections in Open state and ony some of them in Bound state.
You could write in log the number of Open and Bound connections in evClientConnected event handler.

Re: SMPP Server An exception was thrown by a TaskScheduler. ---> System.OutOfMemoryException:

Posted: Tue Jun 30, 2020 4:12 pm
by alt
You can also change InactivityTimeout for connected clients. It helps to save server resources.