cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Script timeout error

KN_9954684
12-Amethyst

Script timeout error

A service is unable to execute completely because the script time configured is less.

 

Written code in catch block of the service.But code in catch block is not executing.

 

Let me know How do I capture Script timeout error in catch block 

11 REPLIES 11
yhan
17-Peridot
(To:KN_9954684)

You can use script log statements(like logger.warn("message") )in the catch block code, then check the log file to know where is the service performed.

KN_9954684
12-Amethyst
(To:yhan)

Have performed what you suggested.

 

But No luck,It is not showing log statements written in Catch block in Script log.

 

I see Script timeout error log for this service in Application Log.

 

But unable to capture it in catch block.

 

 

yhan
17-Peridot
(To:KN_9954684)

Which statement do you use? How about using logger.error("message")?  Can you be sure the service has been executed in that step?

I suggest you can set more statements in different code areas.

KN_9954684
12-Amethyst
(To:yhan)

Yes I am sure ,the service got executed.

 

We are performing for loop 5000 times.

 

I can see the count till 1700 using logger.warn statements in try block.

 

After that it is not able to go further due to script timeout and I tried logger.error("Message") in catch block.But No luck

yhan
17-Peridot
(To:KN_9954684)

I got your point, let me check if we can catch timeout in JS script, then go back to you.

yhan
17-Peridot
(To:KN_9954684)

JS provides two fields on the err that is caught --- err.name and err.message.

you can try below:

try{

//service code

} catch (err){

     if(err.message.indexOf("Timeout") > 0){// do something to address the timeout exception}

}

Other related information you can refer article CS252885

KN_9954684
12-Amethyst
(To:yhan)

var a;
try{
for(var i=0;i<10000000000000;i++)
{
a = 5;
}
result = a;
}
catch(err)
{
if(err.message.indexOf("Timeout") > 0){
logger.error("Timeout");
me.Status = "Failed";
}
}

 

The above code runs more than configured script time.But it is not showing Timeout(Check logger statement above) in logs and it doesn't make Status property as Failed.

 

But it shows general script timeout error as "Execution of Script terminated after : 30 seconds. Timeout configured for 30 seconds."

 

Please try the same code from your end and let me know.I am using ThingWorx 8.5.0-b12

yhan
17-Peridot
(To:KN_9954684)

After further testing and investigation in my environment, seems it isn't possible to handle ScriptTimeoutException from Script Service, you can refer CS341183 . Because ScriptTimeoutException cannot bubble up from backend code to composer code for third-party limitation.

 

 

 

KN_9954684
12-Amethyst
(To:yhan)

Could you let me know if there is any workaround to handle this?

yhan
17-Peridot
(To:KN_9954684)

How about designing the execution logic of the service to fulfill a same business requirement?

For example, at the beginning of the service, set me.status = pending and output message "start executing the service"; At the last of the service, set me.status=success. If the service is not executed successfully and timeout, then me.status will keep pending value.

KN_9954684
12-Amethyst
(To:yhan)

Just checked it with basic service I wrote above.It works great!!

 

Will apply the same with real business logic and Let you know.

 

Thanks!!

 

 

Top Tags