Expression or script hangs when checking variables

Post your questions and help other users.

Moderator: Martin

Post Reply
Markos
Posts: 7
Joined: 01 Dec 2016 11:49

Expression or script hangs when checking variables

Post by Markos » 02 Dec 2016 21:16

Hi,

I have a weird problem when using expressions or scripts to check variables (local or global). Sometimes it works, but more often it doesn't. It happens in different flows, complex or simple. Let me give an example:
I have a flow that triggers on user presence and it makes a http request. After that I have a condition that says: "status_code == 200". Without the quotes of course. Another example:
A flow that sets a global variable inside a script (I checked in the settings that this variable exists afterwards, and it does) and another flow where I check that global variable inside a condition.
Both examples work sometimes (mostly the first 2 times, but that is not consistent either) but mostly the condition stays red and the flow just hangs forever. When I try to stop it manually nothing happens. I have to stop the service and start it again to stop the flow. I tried using an exception in the flow but that was useless because it doesn't go past the condition. And there is no error notification whatsoever - with or without exception handling.
Then I made a test: Inside one flow I deleted the expression and used an if-clause inside an action to check for the variable...and then that action stayed red forever. Somehow Automagic doesn't like that I check for variables and it doesn't matter if it's a condition or an action. The debug log doesn't show anything I'm afraid, so no help there. It's really weird overall.

Apart from nodes checking for variables everything works great. I have a few quite complex flows including checks for cell towers and wifi. I created my own widgets that I fill with data from a http response via json. For example I put weather data in a global variable and send that via tasker plugin to a widget. That works. But checking the status_code in a condition in that same flow freezes everything. I removed the status_code==200 condition in the flow and it just works flawlessly.

I hope I'm just overlooking something simple and it's not a nasty bug.

btw: I have a Samsung Galaxy Note 4 with Cyanogenmod.

P-chu
Posts: 32
Joined: 05 Nov 2016 19:12

Re: Expression or script hangs when checking variables

Post by P-chu » 03 Dec 2016 19:32

Hi Markos,

It may help present a better idea of the problem if you are able to post a representation or screen shot of your flow with that "status_code == 200" condition? I don't know if I can help, but I'm personally curious as to what your "true" and "false" paths do from that stuck condition.
P-chu

Markos
Posts: 7
Joined: 01 Dec 2016 11:49

Re: Expression or script hangs when checking variables

Post by Markos » 04 Dec 2016 08:33

Hey, sure no problem. I made a new flow and exported it so you can test it yourself. It mostly works by manually starting it, but fails after using it the intended way (device off and on). Instead of just failing it hangs at the condition.
Attachments
flow_TestFlow_20161204_092825.xml
(3.76 KiB) Downloaded 732 times

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Expression or script hangs when checking variables

Post by Martin » 04 Dec 2016 12:15

Hi,

Scripts are using a global lock to ensure that not two scripts run at the same time and read/modify variables which could lead to concurrency problems.
Do you have any other script actions or conditions that execute for a very long time? Scripts that contain loops and sleep-functions could lead to the described problem.

Regards,
Martin

Markos
Posts: 7
Joined: 01 Dec 2016 11:49

Re: Expression or script hangs when checking variables

Post by Markos » 04 Dec 2016 16:33

Yes, I have indeed a few flows that fire at the same time/trigger. It sounds like this is the problem.
I guess I have to either delay these flows so they don't start at the same time, or start a flow from inside another flow when it's finished. Or is there another solution?

Will the 'Pause' action cause problems if I set it to 4 hours to prevent triggering a flow more often? I use that at the end of two flows to be more economical. The flows are then red for 4 hours before they can be triggered again, which seemed to work fine.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Expression or script hangs when checking variables

Post by Martin » 06 Dec 2016 14:11

An action Sleep/Pause should not cause any problems. Just another action Script and condition Expression could potentially block another script.
Feel free to send a log to me in case you are not sure if the described problem applies in your case. To do so, go to the preferences of Automagic, enable Debug log and Write log to SD card, wait until the condition is blocked again and then send the log to me: menu->Manage->Log, menu->Send log.

Regards,
Martin

Markos
Posts: 7
Joined: 01 Dec 2016 11:49

Re: Expression or script hangs when checking variables

Post by Markos » 08 Dec 2016 16:43

Thanks Martin, your assumption was spot on. I rearranged the flows, tested it for a few days and the problem is gone.

Post Reply