Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queued script runs executing a command lead to a disallowed recursion #117745

Closed
munterkalmsteiner opened this issue May 19, 2024 · 30 comments · Fixed by #118153
Closed

Queued script runs executing a command lead to a disallowed recursion #117745

munterkalmsteiner opened this issue May 19, 2024 · 30 comments · Fixed by #118153

Comments

@munterkalmsteiner
Copy link

munterkalmsteiner commented May 19, 2024

The problem

I have several blinds that are controlled via a Broadlink RM4 pro remote. I'm sending base64 codes via script, as suggested in the documentation, and can control the blinds individually without issue.

I've used the template platform to define open, close and stop cover commands and grouped the blinds using the "group" platform (see yaml snippets below). I could then open, close and stop blind groups. The send_command script is executed in queued mode.

This worked fine until HA 2024.3 and is broken now in HA 2024.5. Only one blind in the group is following the command (see also error message in the logs reported below).

What version of Home Assistant Core has the issue?

core-2024.5.3

What was the last working version of Home Assistant Core?

core-2024.3

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Broadlink

Link to integration documentation on our website

https://www.home-assistant.io/integrations/broadlink/

Diagnostics information

home-assistant_broadlink_2024-05-19T20-01-20.921Z.log

Example YAML snippet

- platform: group
  name: "East sun shades"
  entities:
    - cover.shade_north_east
    - cover.shade_east

- platform: template
  covers:
    shade_north_east:
      device_class: shade
      friendly_name: "North east"
      optimistic: true
      open_cover:
        service: script.send_broadlink_command
        data:
          command: b64:scCwBACfBgAJEwkUCRMMEQoTCRQJEwoTpBUSCgkUEwoIFQgUCRQTChMKEwoIFBMKCRQIFQgUCRQJFBMKEwoIFRMJFAkTCggVEwoIFAkUCRQJFAgVCBQUCRMKCRQIFAkUCRQJFAkUCBUTCQkUCRQJFAgUCRQJFAkUCRQJFAkTCRQJFBMKCRQTCRQJFAkJFAkUCRMUCRQJCRQJExSkoxQTCgkUEwoIFQgUCRQTChMKEwkJFBMKCRQJFAkTCRQJFBMKEwoI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RQJFAkUCRMJFAkUCRQTCgkTCRQJFAkUCRQIFAkUCRQJFAkUEwkJFAkUCRQTChMJFAoIFBMKCRQJExQJCRQJFBOkoxUTCQkUEwoJFAgVCBQTChUIEwoIFBQJCRQJFAkUCBQJFBQJEwoJFBMJFAkTCgkUEwoIFAkUCRQJFAgVCBQUCRQJCRQJFAkTCRQJFAkUCRQTCQkUCRQJFAkUCBQJFAkUCRQJFAkTFAkJFAkUCRQTChMJFAkJFBMJCRQJFBQJCRQJExSkoxQTCgkUEwoIFAkUCRQTChMKEwkJFBMKCRQIFQgUCRQJFBMKEwoIFBQJEwoTCggVEwkJFAkUCRQJFAgUCRQUCRMKCRQIFAkUCRQJFAkTCRQUCQkUCRQJFAkTCRQJFAkUCRMKEwkUEwoJFAkTCRQUCRQJFAkJFBMJCRQJFBMKCRQJExSjpBQTCggVEwoIFAkUCRQTChMKEwkJFBMKCRQIFQgUCRQJFBMKEwoIFBQJEwoTCggVEwkJFAkUCRQJFAgUCRQUCRMKCRQJEwkUCRQJFAkUCRMUCQkUCRQJFAkTCRQJFAkUCRQJFAgUFAkJFAkUCRQTCRQJEwoJFBMJCRQJFBMKCRQJExSjpBQTCggVEwoIFAkUCRQTChMJFAkJFBMKCBUIFAkUCRQJFBMKEwkJFBQJEwoTCggUFAkJFAkUCRQIFAkUCRQTChMJChMJFAkUCRQJEwkUCRQUCQkUCRQIFAkUCRQJFAkTCRQJFAkUEwoJEwkUCRQTChMKEwkJFBQJCRQJFBMKCBQJFBOkoxUTCggUEwoJFAkUCBUTCRMKEwoJFBMJCRQJFAkUCRQJExQJFAkJFBMKEwkUCQkUEwoJFAkTCRQJFAkUCRQTCRQJCRQJFAkUCRMJFAkUCRQTCgkTCRQJFAkUCRQJEwoTCRQJFAkUEwkJFAkUCRQTChMKEwkJFBMKCRQIFBQJCRQJFBMABdw=

    shade_east:
      device_class: shade
      friendly_name: "East"
      optimistic: true
      open_cover:
        service: script.send_broadlink_command
        data:
          command: b64:scCwBACfBgA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BUTCRMKEwoIFRIKCRQJFAgVCBQJFBMKEwoIFBMKEwoTCQkUEwoIFQkUCBUIFAkUCBUTChIKCRQJFAgUCRQJFAkUEwoIFAkUCRQIFQgUCRQJFAgVCBQJFAkUEwoIFAkUCRQTChMKEgoJFBMKCBQJFBMKCRQTCRMABdw=

Anything in the logs that might be useful for us?

Logger: homeassistant.components.script.send_broadlink_command
Source: helpers/script.py:1934
integration: Scripts ([documentation](https://www.home-assistant.io/integrations/script), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+script%22))
First occurred: 21:44:26 (2 occurrences)
Last logged: 21:44:39
Send broadlink command: Disallowed recursion detected

Additional information

If I run the script in parallel mode, not all blinds seem to receive the command. I receive then the following error messages in the logs:

Logger: homeassistant.components.broadlink.remote
Source: components/broadlink/remote.py:253
integration: Broadlink ([documentation](https://www.home-assistant.io/integrations/broadlink), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+broadlink%22))
First occurred: 18 May 2024 at 08:00:05 (13 occurrences)
Last logged: 21:20:05
Error during remote.send_command: [Errno -4000] Network timeout: No response received within 5s
@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (script) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of script can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign script Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


script documentation
script source
(message by IssueLinks)

@home-assistant
Copy link

Hey there @Danielhiversen, @felipediel, @L-I-Am, @eifinger, mind taking a look at this issue as it has been labeled with an integration (broadlink) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of broadlink can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign broadlink Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


broadlink documentation
broadlink source
(message by IssueLinks)

@felipediel
Copy link
Contributor

The integration causing the issue should be: Scripts (documentation, issues)

@haszek
Copy link

haszek commented May 20, 2024

Hi! I've got the same problem. I use a template to control Modbus lights and covers. In these templates, for the action to open/close/turn on/off, I'm using a script that takes the Modbus register number as an argument. The script is in "queued" mode. Everything worked flawlessly until the 2024.03 or 04 update (I'm not sure which one). Using a single cover or light still works without any problems, but when it is run in an automation for more than one device, I get an error: "Disallowed recursion detected." Only the first cover/light is affected (e.g., the automation to close all covers closes only one).

What is more suspicious is that when I try to close/open a group of covers or activate a light scene using the dedicated UI dialog, everything works. But placing the same group/scene in an automation fails with "Disallowed recursion detected."

@munterkalmsteiner
Copy link
Author

@bdraco is this issue possibly connected to the recent changes making script executions more efficient?

@bdraco
Copy link
Member

bdraco commented May 23, 2024

The only recent change to the recursion detection code was in #116247. You could try reverting that PR, but that doesn't seem likely to be the cause since the effective change there was only to remove duplicate code.

@bdraco
Copy link
Member

bdraco commented May 23, 2024

It looks like the code is nearly the same since it was first added in 65fbcfa so I'm not sure whats going on here

@bdraco
Copy link
Member

bdraco commented May 23, 2024

If we take the sleep out, it will probably fix this issue

diff --git a/homeassistant/helpers/script.py b/homeassistant/helpers/script.py
index c268a21758f..080cc3a1339 100644
@@ -1736,10 +1722,6 @@ class Script:
             # runs before sleeping as otherwise if two runs are started at the exact
             # same time they will cancel each other out.
             self._log("Restarting")
-            # Important: yield to the event loop to allow the script to start in case
-            # the script is restarting itself so it ends up in the script stack and
-            # the recursion check above will prevent the script from running.
-            await asyncio.sleep(0)
             await self.async_stop(update_state=False, spare=run)
 
         if started_action:
diff --git a/tests/components/automation/test_init.py b/tests/components/automation/test_init.py
index edf0eff878b..9286740dea4 100644
--- a/tests/components/automation/test_init.py
+++ b/tests/components/automation/test_init.py
@@ -2733,6 +2733,7 @@ async def test_recursive_automation_starting_script(
                         {"platform": "event", "event_type": "trigger_automation"},
                     ],
                     "action": [
+                        {"delay": "0.1"},
                         {"service": "test.automation_started"},
                         {"service": "script.script1"},
                     ],
@@ -2811,8 +2812,8 @@ async def test_recursive_automation(
                         {"platform": "event", "event_type": "trigger_automation"},
                     ],
                     "action": [
-                        {"event": "trigger_automation"},
                         {"service": "test.automation_done"},
+                        {"event": "trigger_automation"},
                     ],
                 }
             },

but than we will loose some more loop protection and these tests will fail

         - tests/components/automation/test_init.py:2654 test_recursive_automation_starting_script[True-restart-script1: Disallowed recursion detected-parallel-2]
         - tests/components/automation/test_init.py:2783 test_recursive_automation[True-restart]

@bdraco
Copy link
Member

bdraco commented May 23, 2024

there is a race in the _QueuedScriptRun as well .. but not sure its related to this issue

bdraco added a commit that referenced this issue May 23, 2024
There was a race here. We can also use the lock as a context manager which
simplifies the code quite a bit

found while looking at #117745
@bdraco
Copy link
Member

bdraco commented May 23, 2024

I fixed that race in #118002

@bdraco
Copy link
Member

bdraco commented May 23, 2024

there is a race in the _QueuedScriptRun as well .. but not sure its related to this issue

That race is very narrow so I didn't think it was the issue, but after looking at it again, I can't see what else it could be.

Can you try #118002 and see if it solves the problem?

I had to close that PR as it will have other side effects. Best to wait for more information since I can't replicate the problem yet.

@bdraco
Copy link
Member

bdraco commented May 23, 2024

Also, I can't replicate the problem, and since you haven't posted the script in question (or I've missed it somehow), I'm blocked from continuing to investigate until I can see the script and try to write a test for it.

@munterkalmsteiner
Copy link
Author

Here is the script.

sequence:
  - service: remote.send_command
    target:
      entity_id: remote.broadlink_rm4_pro_remote
    data:
      command: "{{ command }}"
      num_repeats: 3
mode: queued
alias: Send broadlink command
max: 10

I've made a bisect and found the first commit in which the bug seems to have been introduced:

[mun@shamrokkV homeassistant]$ git bisect start
status: waiting for both good and bad commits
[mun@shamrokkV homeassistant]$ git bisect good 1aa5a07
status: waiting for bad commit, 1 good commit known
[mun@shamrokkV homeassistant]$ git bisect bad b613976
Bisecting: 898 revisions left to test after this (roughly 10 steps)
[9f19e7339d6f0caccfba1f3dc71642323d6777c3] Improve lists in integrations [P-Q] (#113236)
[mun@shamrokkV homeassistant]$ git bisect good
Bisecting: 449 revisions left to test after this (roughly 9 steps)
[8e1f57f663188c69e3d391738f4e7eca6698e249] Enable Ruff PT023, disable PT011, PT012, PT018 (#113900)
[mun@shamrokkV homeassistant]$ git bisect bad
Bisecting: 224 revisions left to test after this (roughly 8 steps)
[b7f7bed46cf38c1fbe1906c64715b12d98630cdf] Import and create pyudev for usb in the executor (#113478)
[mun@shamrokkV homeassistant]$ git bisect bad
Bisecting: 111 revisions left to test after this (roughly 7 steps)
[0eda6e86c58dda4108f253154a67a373f0129ccc] Add service icons to Freebox (#113298)
[mun@shamrokkV homeassistant]$ git bisect good
Bisecting: 55 revisions left to test after this (roughly 6 steps)
[cd52f0f243694a6d6dc10349bc452d3a5432aac5] Add service icons to Notify (#113417)
[mun@shamrokkV homeassistant]$ git bisect good
Bisecting: 27 revisions left to test after this (roughly 5 steps)
[e0b1531afa34f322c89973ed28e4375ce094f7dd] Remove OpenCV integration (#113455)
[mun@shamrokkV homeassistant]$ git bisect bad
Bisecting: 13 revisions left to test after this (roughly 4 steps)
[dd9fdac51eb026f3d612761d9151da268c62e0d2] Remove unused tts fixture (#113480)
[mun@shamrokkV homeassistant]$ git bisect bad
Bisecting: 6 revisions left to test after this (roughly 3 steps)
[4fb127e5af1fa8a90e581bbc687254b8a40cbe36] Avoid creating another ssl context in cert_expiry (#113467)
[mun@shamrokkV homeassistant]$ git bisect good
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[052d7d1e197b0c509a17a5fe86f7b274810a7080] Fix scene integration doing blocking I/O in the event loop to import platforms (#113391)
[mun@shamrokkV homeassistant]$ git bisect good
Bisecting: 1 revision left to test after this (roughly 1 step)
[92e73312ea101ef9f3029d33c22b5cf4534c8944] Bump `pysnmp-lextudio` to version `6.0.11` (#113463)
[mun@shamrokkV homeassistant]$ git bisect good
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[bdede0e0daa9d518e0781081c0409efbf4d86c8f] Start script runs eagerly (#113190)
[mun@shamrokkV homeassistant]$ git bisect bad
bdede0e0daa9d518e0781081c0409efbf4d86c8f is the first bad commit
commit bdede0e0daa9d518e0781081c0409efbf4d86c8f (HEAD)
Author: J. Nick Koston <nick@koston.org>
Date:   Thu Mar 14 16:53:26 2024 -1000

    Start script runs eagerly (#113190)

 homeassistant/helpers/script.py                               |  3 ++-
 tests/components/fan/common.py                                |  8 ++++++++
 tests/components/homeassistant/triggers/test_numeric_state.py | 10 ++++++++--
 tests/components/homeassistant/triggers/test_state.py         | 10 ++++++++--
 tests/components/template/test_fan.py                         |  1 +
 tests/helpers/test_script.py                                  |  9 ++++++---
 6 files changed, 33 insertions(+), 8 deletions(-)

@munterkalmsteiner
Copy link
Author

munterkalmsteiner commented May 25, 2024

If I revert the change in bdede0e, the script gets executed as expected and I don't receive the recursion detected error.

And I can confirm that the suggestion here does not fix the issue.

If there is any more information I can provide, I'll gladly do so.

@bdraco
Copy link
Member

bdraco commented May 25, 2024

That commit changed the timing to execute the script right away instead of delaying it until the next run of the event loop.

Unfortunately that means we have a race somewhere in the script code that has gone unnoticed.

I haven't been able to find it.

@bdraco
Copy link
Member

bdraco commented May 25, 2024

I guess it could be in broadlink as well and that's why I can't replicate

@bdraco
Copy link
Member

bdraco commented May 25, 2024

Thinking about this some more, before that change we would catch extra runs too late. It could mean there is a problem with locking. It's also possible you have an other automation that is unexpected calling the queued script at the same time.

@bdraco
Copy link
Member

bdraco commented May 25, 2024

I think I'm going to have to get a broadlink device test with, since I spent an hour and a half poking at this and haven't been able to get it to happen

@munterkalmsteiner
Copy link
Author

munterkalmsteiner commented May 25, 2024

Some more info to triangulate this issue:

  1. I've replicated it with a vanilla config, just adding the broadlink integration and configuring two blinds as covers in a group. Hence, nothing else should have interfered here.
  2. As @haszek reported here, he has the same issue with the modbus integration. Maybe they can provide more details to find some commonality with the broadlink setup.
  3. Also as @haszek reported here, the issue does not occur if one triggers the groups through the UI. I can confirm this odd behavior.

@bdraco
Copy link
Member

bdraco commented May 25, 2024

Maybe we have a contextvar leak in the code somewhere....

This one is a bit of a stumper

@haszek
Copy link

haszek commented May 25, 2024

Hi! Yes, I have the same problem. I don't use broadlink integration. I get this error in a script that is using Modbus integration.
The script is:
light_turn_on_plc:
alias: light_turn_on_plc
sequence:

  • service: modbus.write_register
    data_template:
    value: 101
    hub: plc
    slave: 1
    address: '{{ 12288 + offset }}'
    mode: queued
    max: 50
    fields:
    offset:
    selector:
    number:
    min: 1
    max: 100
    name: offset
    required: true

This scrip is used in a template:

  • platform: template
    lights:
    biuro:
    friendly_name: "Biuro"
    unique_id: light_biuro
    value_template: "{{ is_state('sensor.plc_mw_60','1')}}"
    turn_on:
    service: script.light_turn_on_plc
    data:
    offset: 60
    turn_off:
    service: script.light_turn_off_plc
    data:
    offset: 60
    kuchnia:
    friendly_name: "Kuchnia"
    unique_id: light_kuchnia
    value_template: "{{ is_state('sensor.plc_mw_61','1')}}"
    turn_on:
    service: script.light_turn_on_plc
    data:
    offset: 61
    turn_off:
    service: script.light_turn_off_plc
    data:
    offset: 61

When in automation I turn on/off more then one light (it does not matter if there is a group or a scene of lights or lights are added one by one) I get the error "Disallowed recursion detected".
But if I turn on a scene manualy - everthing is OK, the error is not occuring.

@home-assistant
Copy link

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (automation) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of automation can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign automation Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


automation documentation
automation source
(message by IssueLinks)

@bdraco
Copy link
Member

bdraco commented May 26, 2024

I'm having no luck finding the issue. We could revert bdede0e and it will fix it for this case, but it means we are sweeping the problem under the rug instead of fixing the root cause and it will probably come up again the next time we change something else.

@bdraco
Copy link
Member

bdraco commented May 26, 2024

At this point I'm ~7+ hours into investigating this without a viable test case and I think I'm going to have to throw in the towel as I can't find the root cause. I think we need to wait for someone else to take a look who will have another perspective on how to locate the issue. Hopefully its something obvious to someone else and I've made a silly mistake writing the test case or I'm thinking about this the wrong way.

@bdraco bdraco added help-wanted Wanna help? Jump in! and removed integration: automation labels May 26, 2024
@bdraco
Copy link
Member

bdraco commented May 26, 2024

Maybe the problem is already solved and I need to test on 2024.5.5 instead of dev

Test is still successful on 2024.5.5 as well

@bdraco
Copy link
Member

bdraco commented May 26, 2024

I've been working under the assumption this is a bug in the script engine, but maybe its not and it actually is the script calling itself indirectly.

@bdraco bdraco mentioned this issue May 26, 2024
20 tasks
bdraco added a commit that referenced this issue May 26, 2024
I have been investigating #117745 for a few hours and have not been able
to replicate the problem or write a failing test case for it. The logging
does not show the stack so it is difficult to figure out where the recursion
is coming from.
@bdraco
Copy link
Member

bdraco commented May 26, 2024

#118151 will log the stack when this hit the disallowed recursion so we can tell if the script is getting called in a loop somehow or there is an actual bug in the script code or the problem is somewhere else

@bdraco
Copy link
Member

bdraco commented May 26, 2024

I just found #117251 which has a smaller reproducer. I'll try to write a test with that

@bdraco
Copy link
Member

bdraco commented May 26, 2024

I was able to write a test from the reproducer in that issue #118153

@bdraco
Copy link
Member

bdraco commented May 26, 2024

Maybe we have a contextvar leak in the code somewhere....

That is looking more likely based on #117251 (comment)

I'm going to close this issue as a duplicate of #117251 since we have a reproducer in there. Please continue in that issue as its the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants