Problem/Motivation

If a "Create" form has a field that kicks off an Ajax call (e.g. an image upload field), the $leaf_lifetime can easily exceed 60 seconds, causing a fatal error:

AssertionError: assert($leaf_lifetime <= 60) in assert() (line 97 of /app/web/modules/contrib/subgroup/src/Entity/GroupSubgroupHandler.php)

Steps to reproduce

  1. Create subgroup with an image field.
  2. Go to form to create a subgroup entity.
  3. Fill in required fields.
  4. Choose an image so it gets added to form via Ajax (showing the Alt field).
  5. Wait more than 60 seconds.
  6. Hit "Save" button.

This will cause the error here because apparently $child->getCreatedTime() gets set when the Ajax call is made:

$leaf_lifetime = $this->time->getCurrentTime() - $child->getCreatedTime();
assert($leaf_lifetime <= 60);

Proposed resolution

Somehow make sure that $child->getCreatedTime() does not get set with Ajax calls made before the entity is actually saved.

Remaining tasks

Create patch.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#2 3180508-2.leaf-lifetime-fix.patch805 bytesjrb

Comments

jrb created an issue. See original summary.

jrb’s picture

Status: Active » Needs review
StatusFileSize
new805 bytes

I've attached a patch that makes the leaf lifetime calculation use $child->getChangedTime() rather than $child->getCreatedTime(). This fixes the problem that we're seeing with the Ajax callback because the "changed time" looks to be reset when the entity is actually saved.

Would this still prevent whatever it is that the assert() is trying to prevent?

kristiaanvandeneynde’s picture

The reason we check vs created time is because you really should not be adding existing groups into a tree unless you absolutely know what you're doing. That's why it's an assert rather than an exception, as you can ignore asserts on production but they really ought to show up during development and testing.

Having said that, if the entity's create time is indeed set as soon as the form is loaded and you're using the right form (as explained in the IS), I can see how people will hit the 60 second limit. So what we could do, is make sure the entity's create time is set during form submit, rather than form instantiation.

kristiaanvandeneynde’s picture

Priority: Major » Normal
Status: Needs review » Needs work
scotwith1t’s picture

In our situation,

you really should not be adding existing groups into a tree unless you absolutely know what you're doing

was not relevant. Rather than adding existing groups into a tree, we were simply creating a new subgroup and by the time I fill out the form (there are a handful of content fields for each group on this build, all needed for the front-end display of the group), we hit this assert almost every single time. Not sure if it was that or just the fact that we are using Paragraphs heavily on the Group entity and thus the ajax call was the culprit even if we quickly filled out the form, but the patch works as expected/advertised. Thx!

jrb’s picture

Status: Needs work » Closed (outdated)

This assert() was removed in #3163044: Leaf lifetime exceeds 60s in large migrations, so this is no longer an issue in any branch (1.x, 2.x, and 3.x).