Forum C# Aborted code because it ran for too long.

Aborted code because it ran for too long.

Postby Vudermar » January 18th, 2018, 12:30 pm

Hello!
We sometimes have errors from many places: Aborted code because it ran for too long. (2 - 3 seconds)
But our code should not be executed for so long.
Our logic is executed within the critical section. But the lock object is only one and therefore can not be deadlock from our side.
We have many places where it stops at System.Array.Copy.
For example:
Code: Select all
System.Threading.ThreadAbortException: Thread was being aborted.
   at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
   at System.Collections.Generic.List`1.ToArray()
   at GameModel.Field.GameModel.IField_forCommands.RemoveAllKilledCards()
   at GameModel.TurnCommand.GameModel.ITurnCommand.Execute()
   at GameModel.Turn.GameModel.ITurn.Execute()
   at GameModel.Model.GameModel.IModel.Simulate(sPos pos, eDir direction, dOnSimulateQuestions strategy)
   at GameRoom.State_Fight_WaitingPlayerAction.MakeMoveTurnStrategy.GameRoom.State_Fight_WaitingPlayerAction.IMakeTurnStrategy.MakeTurn()
   at GameRoom.State_Fight_WaitingPlayerAction.TryToMakeTurn(IMakeTurnStrategy strategy)
   at GameRoom.State_Fight_WaitingPlayerAction.OnPlayerGotMessage(ePlayer playerType, NetMessage msg)
   at GameRoom.GameRoom.OnPlayerGotMesage(NetMessage msg, ePlayer player)
   at GameRoom.GameRoom.OnPlayerGotMessage(NetMessage msg, IPlayer player)
   at NetWork.UserPlayer.OnGotMessage(PIOPlayer player, Message message)
   at NetWork.Room.NetWork.IRoom.GotMessage(PIOPlayer player, Message message)
   at NetWork.PIORoom.GotMessage(PIOPlayer player, Message message)

Less often we have problems with the critical section:
Code: Select all
System.Threading.ThreadAbortException: Thread was being aborted.
   at System.Threading.Monitor.Enter(Object obj)
   at NetWork.Room.TimerCallbackExt.<Execute>b__5_0()


May be there are something special in working with the critical sections and player.io.
May be a garbage collector is locking a thread.
These are our ideas.

Сan someone help?
Thanks.
Vudermar
 
Posts: 1
Joined: May 4th, 2017, 10:33 am

Re: Aborted code because it ran for too long.

Postby Henrik » January 30th, 2018, 9:48 am

Hey Vudermar,

It's probably not execution that takes time, but waiting for the lock to be free. Locking is free-for-all, so if a thread is unlucky, it might never get the lock if there's a continuous flow of events that trigger the same code and try to grab the same lock. And when a thread has been waiting for too long, it will be aborted.

As always, try to reduce the amount of code that is covered by a lock, and try to avoid locking in the first place. I don't know exactly what you're doing inside your lock, but you might want to research if there are lockless alternatives to the algorithm you're using.
Henrik
.IO
 
Posts: 1831
Joined: January 4th, 2010, 1:53 pm


Return to C#



cron