Race condition in task

162 views
Skip to first unread message

Daniel Matthews

unread,
Nov 3, 2023, 8:07:49 AM11/3/23
to tas...@googlegroups.com
I've got a task set to allow multiple instances ("Run Both") in it's collision handing setting.

In that task it can add an item to an array.

I'm seeing that sometimes the second instance of the task does not get the updated array contents so is logically incorrect.

Is there a way of allowing the task to run multiple instances but ensuring the second instance doesn't run until the first finishes?

Thanks

On Fri, 3 Nov 2023, 08:10 , <tas...@googlegroups.com> wrote:
Riwer Olmus <olm...@gmail.com>: Nov 02 12:41PM -0700

Hey I am trying to do a https request to an app (already tested on other
api testing services ) and I am getting this error, any help?
 
20.36.58/LicenseCheckerTasker Checking cached only
20.36.58/LicenseCheckerTasker cache validity left -675784
20.36.58/LicenseCheckerTasker Cached status: Licensed
20.36.58/LicenseCheckerTasker Cached only: Licensed
20.36.58/Ew add wait type EasyAction1 time 2147483647
20.36.58/Ew add wait type EasyAction1 done
20.36.58/E add wait task
20.36.58/E Error: 1
20.36.58/E
[image: Imagen de WhatsApp 2023-11-02 a las 20.38.25_4c91492f.jpg]
 
 
 
Working on insomnia:
"João Dias" <joao...@gmail.com>: Nov 02 03:29PM

Hi. Maybe your system limits how many notifications an app can post? Can
you try posting 1 every 10 seconds for example, and see if that always
works?
 
Thank you for your contact.
 
*Join*
<https://play.google.com/store/apps/details?id=com.joaomgcd.join&referrer=utm_source%3Djoaoappssupport%26utm_medium%3Demail%26utm_campaign%3Dsignature%26anid%3Dadmob>:
connect multiple devices (send pushes, remote SMS, notifications) on
Android, Windows, Mac, Linux
 
<https://play.google.com/store/apps/details?id=com.joaomgcd.join&referrer=utm_source%3Djoaoappssupport%26utm_medium%3Demail%26utm_campaign%3Dsignature%26anid%3Dadmob>
*Tasker*
<https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm&referrer=utm_source%3Djoaoappssupport%26utm_medium%3Demail%26utm_campaign%3Dsignature%26anid%3Dadmob>:
customize/automate anything on your phone!
 
<https://play.google.com/store/apps/details?id=com.joaomgcd.join&referrer=utm_source%3Djoaoappssupport%26utm_medium%3Demail%26utm_campaign%3Dsignature%26anid%3Dadmob>
*AutoApps*
<https://play.google.com/store/apps/details?id=com.joaomgcd.autoappshub&referrer=utm_source%3Djoaoappssupport%26utm_medium%3Demail%26utm_campaign%3Dsignature%26anid%3Dadmob>:
add advanced functionality to Tasker via plugins
 
<https://www.patreon.com/joaoapps>
 
João Dias
 
 
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to tasker+un...@googlegroups.com.

aa6vh

unread,
Nov 3, 2023, 10:29:58 AM11/3/23
to Tasker
One way to accomplish this is to use a flag. In the task, first check a global variable, and if set, wait until it becomes unset. If unset, set it, do what it needs to do, then clear that global.

Maurelio Neves

unread,
Nov 3, 2023, 1:35:26 PM11/3/23
to tas...@googlegroups.com
Kie yctty

Maurelio Neves
📞(21) Kidly a  sua re de tf

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tasker/1e127811-a798-4576-a933-04004578c842n%40googlegroups.com.

Rich D

unread,
Nov 3, 2023, 5:25:06 PM11/3/23
to Tasker

I'm seeing that sometimes the second instance of the task does not get the updated array contents so is logically incorrect.

Is there a way of allowing the task to run multiple instances but ensuring the second instance doesn't run until the first finishes?



You can make your Task iterations run in a first in first out order by launching them with a Event context and having 'Enforce Task Order' enabled in the profile properties.   There is a example of this approach in this Post.  It is under section 8.





Daniel Matthews

unread,
Nov 4, 2023, 4:37:19 PM11/4/23
to tas...@googlegroups.com
Thanks so much for the replies.

I had forgotten the "Enforce Task Order" setting, I had already had that set on yet, my task is definitely running concurrently and not sequentially, it doesn't happen every time but certainly on a daily basis.

Thanks also for the taskershare link, I've imported the task and it's working per your instructions so I'm confused why my task doesn't respect the "enforce task order" setting.

I do appreciate I can set a global var and a wait to force execution but it seems a bit of a hack especially when tasker has the above setting.

Rich D

unread,
Nov 5, 2023, 4:22:01 AM11/5/23
to Tasker Google Groups Post


Thanks also for the taskershare link, I've imported the task and it's working per your instructions so I'm confused why my task doesn't respect the "enforce task order" setting.



Could you post the exported description of your profile?




To post your profile or task here...  Long press on the profile or task name -> ( 3 dot menu with 4.0+ ) Export -> Export "DESCRIPTION" to clipboard (not XML) -> 'Four Space' option (for proper formating in reddit)

Any linked tasks will be exported with the profile they are linked to..

To be able to export, the profile needs to be named by you (Not the Tasker listed name.  Tasker will list your profile with the context name if you have not given it one). 

    !!!  Be sure to review the Description and remove any personal information !!!

On older Tasker versions you might need to disable beginner mode in the Tasker preferences. Beginner mode has been removed from the latest Tasker release. 


Daniel Matthews

unread,
Nov 7, 2023, 6:43:46 AM11/7/23
to tas...@googlegroups.com
Hi Rich, peeps,

Here's the export:

Step 10 in the task is a debug output which when the issue occurs will output the same notification content and id buy a different timestamp so the task is running concurrently wh|not shouldn't, this is even with variable logic to manually 'lock' the task when in progress.

    Profile: Read New Notification
    State: Variable Value  [ %PACTIVE ~ *Buds* | %PACTIVE ~ *Car* ]
    Event: AutoNotification Intercept [ Configuration:Event Behaviour: true
    Notification Type: Only Created Notifications
    Persistency Type: Non-Persistent Only
    Ignore Group Summaries: true ]
    
    
    
    Enter Task: Read Notification
    Settings: Run Both Together
    
    <Wait until previous instance ends (& resets the var)>
    A1: Wait Until [
         MS: 0
         Seconds: 10
         Minutes: 0
         Hours: 0
         Days: 0 ]
        If  [ %ReadNotificationTask_Running = 0 ]
    
    <Set locking var>
    A2: Variable Set [
         Name: %ReadNotificationTask_Running
         To: 1
         Do Maths: On
         Max Rounding Digits: 3
         Structure Output (JSON, etc): On ]
    
    A3: Variable Convert [
         Name: %anapp
         Function: To Lower Case
         Store Result In: %appNameLowered
         Mode: Default ]
    
    <Check if app is on ignore list>
    A4: Variable Set [
         Name: %index
         To: %ReadNotificationAppBlacklist(#?%appNameLowered)
         Do Maths: On
         Max Rounding Digits: 3 ]
    
    A5: If [ %index > 0 ]
    
        A6: Variable Set [
             Name: %ReadNotificationTask_Running
             To: 0
             Do Maths: On
             Max Rounding Digits: 3
             Structure Output (JSON, etc): On ]
    
        A7: Stop [ ]
    
    A8: End If
    
    <Check if notification content is in recent list>
    A9: Variable Set [
         Name: %index
         To: %RecentNotifications(#?%antext)
         Structure Output (JSON, etc): On ]
    
    <Debug>
    A10: Notify [
          Title: [%anid] Search, position: %index, time: %TIMEMS
          Text: [%anapp] %antext
          Number: 0
          Priority: 3
          LED Colour: Red
          LED Rate: 0
          Category: Debug Notifications ]
    
    <Prevent same notification firing more than once>
    A11: If [ %index > 0 & %PreventDuplicateNotifications = 1 ]
    
        A12: Variable Set [
              Name: %DedupeCountToday
              To: %DedupeCountToday + 1
              Do Maths: On
              Max Rounding Digits: 3
              Structure Output (JSON, etc): On ]
    
        A13: Variable Set [
              Name: %ReadNotificationTask_Running
              To: 0
              Do Maths: On
              Max Rounding Digits: 3
              Structure Output (JSON, etc): On ]
    
        A14: Stop [ ]
    
    A15: End If
    
    <Ignore Main Tasker (Active Profiles) Notification>
    A16: If [ %anapp eq Tasker & %antext ~ *active profiles* |+ %antext ~ *BT*Buds* |+ %antext ~ *Buds*BT* |+ %antext ~ *Car* ]
    
        A17: Variable Set [
              Name: %ReadNotificationTask_Running
              To: 0
              Do Maths: On
              Max Rounding Digits: 3
              Structure Output (JSON, etc): On ]
    
        A18: Stop [ ]
    
    A19: End If
    
    <Ignore notifications about dedupes if config dictates>
    A20: If [ %AnnounceDedupeAlert = 0 & %antitle ~ *De-dupe* ]
    
        A21: Variable Set [
              Name: %ReadNotificationTask_Running
              To: 0
              Do Maths: On
              Max Rounding Digits: 3
              Structure Output (JSON, etc): On ]
    
        A22: Stop [ ]
    
    A23: End If
    
    <Add new item to top of array of notifications for dupe check>
    A24: Array Push [
          Variable Array: %RecentNotifications
          Position: 1
          Value: %antext ]
    
    <Delete 11th item from array if it exists>
    A25: Array Pop [
          Variable Array: %RecentNotifications
          Position: 11 ]
        If  [ %RecentNotifications(#) > 10 ]
    
    A26: Perform Task [
          Name: Say: message, time, battery, no log
          Priority: %priority+1
          Parameter 1 (%par1): %anapp %antitle ]
        If  [ %antext !Set ]
    
    A27: Perform Task [
          Name: Say: message, time, battery, no log
          Priority: %priority+1
          Parameter 1 (%par1): %anapp %antitle %antext ]
        If  [ %antext Set ]
    
    <Reset locking var>
    A28: Variable Set [
          Name: %ReadNotificationTask_Running
          To: 0
          Do Maths: On
          Max Rounding Digits: 3
          Structure Output (JSON, etc): On ]
    
    

Rich D

unread,
Nov 8, 2023, 5:31:34 AM11/8/23
to Tasker Google Groups Post
I believe the issue could be in your coding. Before we can start to check for a Tasker bug I would do more debugging on this task.  The first potential issue I see you are using the Array Search function to set a variable.

 %ReadNotificationAppBlacklist(#?%appNameLowered)

Then you test the results of the variable 


 A5: If [ %index > 0 ]


If there are multiple matches to the search that variable can contain a comma separated list of all the matched indexes and will not test correctly. I will usually test for a comma in the variable as well to see if there are more than 1 matches.

 A5: If [ %index > 0 ]    OR   IF:  %index ~ *,*


The other issue is even though you have "Ignore Group Summaries " checked in the autonotification context. Some Notifications (such as Telegram) can still trigger multiple times for the same notification with the same notification ID.

I would suggest actually writing the data to a log file file for better debugging. Be sure to log all of the "Text"  elements available in the autonotification variables.  You should also be checking the run log as this would show a multiple activation for the same notification.


Thanks,    Rich.. 




Rich D

unread,
Nov 8, 2023, 6:04:39 AM11/8/23
to Tasker Google Groups Post
Check here for more details.. 

Daniel Matthews

unread,
Nov 8, 2023, 11:29:16 AM11/8/23
to Tasker
Thanks so much Rich, interesting note about the array search result. I've amended my task to use %anwhentime and will let you know how it behaves.

Daniel Matthews

unread,
Nov 11, 2023, 6:23:57 PM11/11/23
to tas...@googlegroups.com
Thanks Rich for the array search info.

I've implemented the use of %anwhentime and it seems to be working fine and it's much cleaner.

I think there is a bug somewhere that the original implementation hit as the array couldn't ever have had more than one copy of the notif content but honestly the new code is much nicer anyway.

Cheers 

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/KVFHm4psyuk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tasker/577a6009-7013-4aef-ba33-a6560406ea3dn%40googlegroups.com.

Rich D

unread,
Nov 12, 2023, 7:33:28 AM11/12/23
to Tasker Google Groups Post
Glad you got it working.... :)
Reply all
Reply to author
Forward
Message has been deleted
0 new messages