Rule execution timing out, WSOD, errors

Created on 28 May 2022, over 2 years ago
Updated 24 November 2023, 12 months ago

Problem/Motivation

Hello,
I'm not sure whether this is a bug or a config issue on my part with a rule. Here's what's happening; I have a simple rule that does some math on two fields in a bundle, then puts the result into another field. If I have the rule react "After saving a new content item entity of type Classified Ad" it works fine. If I change it to run either "After updating a content item entity of type Classified Ad" or "Before saving a content item entity of type Classified Ad" the site goes to a WSOD after the PHP timeout period.

In the first instance when it works, I get this in the log:

Rules evaluation log-Close all-
Reacting on event After saving a new content item entity.
0 ms Reacting on event After saving a new content item entity.
0.044 ms Evaluating conditions of rule Rule. [edit]
7.001 ms The condition Entity is of bundle evaluated to TRUE. [edit]
7.478 ms The condition NOT Data value is empty evaluated to TRUE. [edit]
7.56 ms Condition set (AND) evaluated to TRUE.
Rule Rule fires. [edit]
0 ms Rule Rule fires.
14.232 ms Evaluating the action Calculate a numeric value. [edit]
15.73 ms Evaluating the action Set a data value. [edit]
16.175 ms Rule Rule has fired.
23.828 ms Finished reacting on event After saving a new content item entity.

In the 2nd & 3rd instances I don't get any Rules log messages, only this:

https://mysite/admin/config/workflow/rules
Message	Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction: INSERT INTO "cache_discovery" ("cid", "expire", "created", "tags", "checksum", "data", "serialized") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6) ON DUPLICATE KEY UPDATE "cid" = VALUES("cid"), "expire" = VALUES("expire"), "created" = VALUES("created"), "tags" = VALUES("tags"), "checksum" = VALUES("checksum"), "data" = VALUES("data"), "serialized" = VALUES("serialized"); Array ( [:db_insert_placeholder_0] => last_write_timestamp_cache_discovery [:db_insert_placeholder_1] => -1 [:db_insert_placeholder_2] => 1653741731.784 [:db_insert_placeholder_3] => [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => d:1653741731.7850000858306884765625; [:db_insert_placeholder_6] => 1 ) in Drupal\Core\Cache\DatabaseBackend->doSetMultiple() (line 273 of /home/mysite/public_html/core/lib/Drupal/Core/Cache/DatabaseBackend.php).

Here's the config of the working rule:

uuid: 02ff2505-aab9-4e4e-ba3c-a32df440d73a
langcode: en
status: true
dependencies: {  }
id: bsgc_s_cut
label: 'BSGC''s Cut'
events:
  -
    event_name: 'rules_entity_insert:node--classified_ad'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: c1e62ef7-5823-4aa6-a537-48a83fe15d3f
  weight: 0
  conditions:
    id: rules_and
    uuid: 6f1e2922-be8e-4428-9986-870a4845166f
    weight: 0
    conditions:
      -
        id: rules_condition
        uuid: 8650db74-ce82-46c9-8b47-125ab052ac7f
        weight: 0
        condition_id: rules_entity_is_of_bundle
        negate: false
        context_values:
          type: node
          bundle: classified_ad
        context_mapping:
          entity: node
        context_processors:
          type:
            rules_tokens: {  }
          bundle:
            rules_tokens: {  }
        provides_mapping: {  }
      -
        id: rules_condition
        uuid: 8d9cd1bb-3abb-4d3c-bd87-091e767aa362
        weight: 0
        condition_id: rules_data_is_empty
        negate: true
        context_values: {  }
        context_mapping:
          data: node.field_ad_price.value
        context_processors: {  }
        provides_mapping: {  }
  actions:
    id: rules_action_set
    uuid: b6b8a690-7279-4563-b8ce-f96f1f10b74d
    weight: 0
    actions:
      -
        id: rules_action
        uuid: 9d0880ba-156e-4157-9a53-5b6f3a60aa78
        weight: 0
        action_id: rules_data_calculate_value
        context_values:
          operator: '*'
        context_mapping:
          input_1: node.field_ad_price.value
          input_2: node.field_multiplier.value
        context_processors:
          operator:
            rules_tokens: {  }
        provides_mapping:
          result: bsgc_cut_value
      -
        id: rules_action
        uuid: 3c714d21-9dc0-4b95-b14a-7cf9408689fa
        weight: 0
        action_id: rules_data_set
        context_values: {  }
        context_mapping:
          data: node.field_bsgc_cut.value
          value: bsgc_cut_value
        context_processors: {  }
        provides_mapping: {  }

And here's the config of the non-working rule:

uuid: 6f5af2f0-271c-413d-bfe0-57912f74528e
langcode: en
status: false
dependencies: {  }
id: bsgc_cut_update
label: 'BSGC Cut Update'
events:
  -
    event_name: 'rules_entity_update:node--classified_ad'
description: ''
tags: {  }
config_version: '3'
expression:
  id: rules_rule
  uuid: 678b7ae0-85e8-4f99-bf87-9b37047995e6
  weight: 0
  conditions:
    id: rules_and
    uuid: a1394d5a-ac0d-4c96-870d-b77804cf338c
    weight: 0
    conditions:
      -
        id: rules_condition
        uuid: 52d00bc2-2a83-4938-9d1a-934d26a2fc8c
        weight: 0
        condition_id: rules_entity_is_of_bundle
        negate: false
        context_values:
          type: node
          bundle: classified_ad
        context_mapping:
          entity: node
        context_processors:
          type:
            rules_tokens: {  }
          bundle:
            rules_tokens: {  }
        provides_mapping: {  }
      -
        id: rules_condition
        uuid: c6d86e38-ae42-449c-95f8-4870f37870bf
        weight: 0
        condition_id: rules_data_is_empty
        negate: true
        context_values: {  }
        context_mapping:
          data: node.field_ad_price.value
        context_processors: {  }
        provides_mapping: {  }
  actions:
    id: rules_action_set
    uuid: 56bcdc87-88c3-4b62-8479-c67fb506a971
    weight: 0
    actions:
      -
        id: rules_action
        uuid: 92860153-430d-4544-9095-3c24828708f7
        weight: 0
        action_id: rules_data_calculate_value
        context_values:
          operator: '*'
        context_mapping:
          input_1: node.field_ad_price.value
          input_2: node.field_multiplier.value
        context_processors:
          operator:
            rules_tokens: {  }
        provides_mapping:
          result: result_1
      -
        id: rules_action
        uuid: 75bf9764-39b4-414e-ad46-d8dfd05dcc94
        weight: 0
        action_id: rules_data_set
        context_values: {  }
        context_mapping:
          data: node.field_bsgc_cut.value
          value: result_1
        context_processors: {  }
        provides_mapping: {  }

The two rules are identical except for when they fire. Is there something I've done wrong, a bug, or some other issue? Any help would be greatly appreciated.

Thanks!

-=Delty

πŸ› Bug report
Status

Closed: works as designed

Version

3.0

Component

Rules Core

Created by

πŸ‡ΊπŸ‡ΈUnited States Delty

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡³China splash112

    You might send your site in an infinite loop, where the same rule gets called time after time?

  • πŸ‡ΊπŸ‡ΈUnited States Delty

    Good thought - I'll dig into it a bit more and see what I can come up with.

    Thanks!

    -=Delty

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    Drupal does not allow modifications to an entity's data during an update. You can use the update event to alter data other than the entity that is being updated, but if you want to modify the entity that is being updated you need to use a after saving event.

    See hook_entity_update(). The documentation for that hook says:

    Respond to updates to an entity.

    This hook runs once the entity storage has been updated. Note that hook implementations may not alter the stored entity data.

    (where I have added the emphasis).

    You need to choose an appropriate event at all times, but particularly in the case where you are acting on a specific piece of content being modified and are then trying to modify that same specific content again in the process, thereby triggering another event.

    Recursion prevention should be possible (we did it in D7) but no one has worked on this in the current version. Regardless, recursion prevention won't make it work properly, it will just make it fail gracefully.

  • Status changed to Closed: works as designed 12 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
Production build 0.71.5 2024