I have a stand alone console app which uses the SPS SDK (4.3.5).
I am basically trying to clone an order, using the following code. However, I frequently get an exception thrown when I call os.NewOrder(spec) due to a timeout. Typically, clients can control timeouts whether it be an ado.net connection attempt or a command timeout for execution duration. Does the SPS SDK offer something similar where the client can basically say "I'm willing to wait X seconds for this operation to complete" ? Is there something I can put in my .exe's App.Config file, perhaps ? Maybe a server setting that I can adjust the behavior of my environment ?
static private IOrder CreateNewOrder(SelectServer ss, IOrderStore os, string srcOrderNumber)
{
// Create an order number, and specify a template to overlay, as well as another order to overlay
OrderCreationSpec spec = new OrderCreationSpec();
spec.BaseNumber = DateTime.Now.ToString("TSyyyyMMddHHmmss");
spec.Templates.Add(srcOrderNumber);
IOrder order = null;
try
{
order = os.NewOrder(spec); // << --- Timeout occurs here sometimes.
// Save the order in the database.
os.ApplyChanges(order);
}
catch (Exception ex)
{
if (order != null)
{
var msgs = order.GetMessages();
Logger.Error($"{msgs?.FirstOrDefault()}", ex);
}
}
return order;
}
Unfortunately there is no way to alter the timeout values for the order store from the config file. Can I see the event information for the error and stack trace so I review the error fully? Thanks.
The exception caught is a System.AggregateException with a count = 1. Its stack trace is the following:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.NewOrder(OrderCreationSpec spec, IProgress`1 progressCallback, CancellationToken cancel)
at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.NewOrder(OrderCreationSpec spec, IProgress`1 progressCallback)
at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.NewOrder(OrderCreationSpec spec)
at SPSOrderCloner.Program.CreateNewOrder(SelectServer ss, IOrderStore os, String srcOrderNumber, String prefix) in C:\dev\ITCSource\Software Engineering Utilities\SPSOrderCloner\SPSOrderCloner\Program.cs:line 223
There exists only 1 InnerException in the InnerExceptions collection:
Message = One or more errors occurred.
StackTrace =
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at SoftPro.OrderTracking.Client.Orders.OrderStore.<>c__DisplayClass40_0.<SoftPro.OrderTracking.Client.Orders.IOrderStore.NewOrder>b__0(Task`1 t2, Object p)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
That InnerException has a defined InnerException of his own:
Message = "The operation has timed out"
StackTrace =
at SoftPro.Select.Client.Runtime.ServerTaskHelper.Run[T](Object obj)
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
There are no further InnerException children.
Thank you for your diagnosis. Lmk if you need additional information.
Select 4.3.5 had a bug where after an order is saved, it may take a brief period of time before that order's version is available from the order store. If you saved the original order then very quickly tried to open the order (your code is doing this under the covers), it may not be available and throw an exception (SoftPro.OrderTracking.Client, OrderNotFoundException).
You might want to test that the order is available by attempting to open the order as read-only. If an exception is thrown, try again after a one second delay then progressively larger delays until you reach a crazy number - like trying for a total of 30 seconds.
*** This bug is fixed in Select version 4.3.11. ***
However, my "source" order was not recently created, and has been existing for some time. The upstream calling logic is fed a CSV list of order numbers that were fetched from the database awhile ago. And the method that I displayed here simply accepts that next order number in the list and clones it using the logic shown.
So while it does not seem that this matches the behavior you described, I'll try and retry the order creation after a small wait just to see if I can improve the behavior.
I've also tried opening the source order in read-only mode, then close it, before then attempting to clone it [in the hopes of placing it in whatever caching is going on internally, hopefully making for a quicker read operation, and thereby avoiding the timeout?). (This read-then-write logic seems closer to the behavior you mentioned...)
Thanks for such a thorough response. I agree that we are talking about different things. I will pass your issue up the line and if I hear anything regarding a resolution, I will let you know.