Magento2: Running cron jobs fails if database name is too long

Created on 9 Apr 2019  路  10Comments  路  Source: magento/magento2

Preconditions (*)

Database is called
shop_test_com_testing_foo_de

You have crontab.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
    <group id="update_virtual_attributes">

Steps to reproduce (*)

  1. bin/magento cron:run -v

Expected result (*)

works

Actual result (*)

doesn't

  [Magento\Framework\Exception\InputException]                                             
  Lock name too long: shop_test_com_testing_foo_de|CRON_GROUP_update_virtual_attribute...  


Exception trace:
 () at /var/www/html/shop.test.com.testing.foo.de/web/vendor/magento/framework/Lock/Backend/Database.php:156
 Magento\Framework\Lock\Backend\Database->addPrefix() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/magento/framework/Lock/Backend/Database.php:66
 Magento\Framework\Lock\Backend\Database->lock() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php:259
 Magento\Cron\Observer\ProcessCronQueueObserver->lockGroup() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php:241
 Magento\Cron\Observer\ProcessCronQueueObserver->execute() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/magento/framework/Event/Invoker/InvokerDefault.php:72
 Magento\Framework\Event\Invoker\InvokerDefault->_callObserverMethod() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/magento/framework/Event/Invoker/InvokerDefault.php:60
 Magento\Framework\Event\Invoker\InvokerDefault->dispatch() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/magento/framework/Event/Manager.php:66
 Magento\Framework\Event\Manager->dispatch() at /var/www/html/shop.test.com.testing.foo.de/web/generated/code/Magento/Framework/Event/Manager/Proxy.php:95
 Magento\Framework\Event\Manager\Proxy->dispatch() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/magento/framework/App/Cron.php:86
 Magento\Framework\App\Cron->launch() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/magento/module-cron/Console/Command/CronCommand.php:117
 Magento\Cron\Console\Command\CronCommand->execute() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/symfony/console/Application.php:835
 Symfony\Component\Console\Application->doRunCommand() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/magento/framework/Console/Cli.php:102
 Magento\Framework\Console\Cli->doRun() at /var/www/html/shop.test.com.testing.foo.de/web/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at /var/www/html/shop.test.com.testing.foo.de/web/bin/magento:23
Fixed in 2.3.x Format is valid

Most helpful comment

This is not expected behaviour. With constraints Magento creates a shorter name when they are too long. It should do the same here.

All 10 comments

Hi @amenk. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@amenk do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

Hi @amenk thank you for you report, this is expected behavior, please refer to -> https://dev.mysql.com/doc/refman/5.7/en/locking-functions.html

@amenk MySQL 5.7 and later enforces a maximum length on lock names of 64 characters. Previously, no limit was enforced.

Thanks for the info --- but can't we then just create the lock name in another way? For example by hashing it ? What is the maximum table name length? then we should enforce a shorter cron group name or so ...

This is not expected behaviour. With constraints Magento creates a shorter name when they are too long. It should do the same here.

I am able to replicate this, but it is manifesting in a confusing admin panel with no menu items loading. The error was being thrown in the log and changing to developer mode threw the error and it would seem it is because my database schema name is 40 characters long, so when the Database lock is loaded, when the prefix is added, the length is greater than 64 and the error is being thrown.
see \Magento\Framework\Lock\Backend\Database::addPrefix

image

Is there a way we can trim the lock name to keep it under 64 to avoid hours of confusion in the future? That would be great.

@engcom-backlog-nazar can you reopen this issue?
This is not expected behaviour. With constraints Magento creates a shorter name when they are too long. It should do the same here.

Also... see this example of a lock
BLOCK_4d0fde89c53949f89f741386ae575b1d704f9a24-old-price-225261-widget-product-grid-final_price-EUR-20191104-1-0-
Even a db name the size of 1 character would cause the lock to fail

Hi @amenk. Thank you for your report.
The issue has been fixed in magento/magento2#25472 by @vpashovski in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.5 release.

Was this page helpful?
0 / 5 - 0 ratings