Skip to content

Scheduler - Invalid TTL exception when defining expiration for stateful lock #58881

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

Open
michalananapps opened this issue Nov 14, 2024 · 1 comment

Comments

@michalananapps
Copy link

michalananapps commented Nov 14, 2024

Symfony version(s) affected

6.4..14

Description

When using the Symfony Scheduler component in a stateful configuration with a Doctrine DBAL lock, an exception is thrown due to an invalid TTL computation in Symfony\Component\Scheduler\Generator\Checkpoint::release.

Symfony\Component\Lock\Exception\InvalidTtlException

"Symfony\Component\Lock\Store\DoctrineDbalStore::putOffExpiration()" expects a TTL greater or equals to 1 second. Got "-190.06952309608".

The issue originates in the following line of code:

        } elseif ($remaining = $this->lock->getRemainingLifetime()) {
            $this->lock->refresh((float) $nextTime->format('U.u') - (float) $now->format('U.u') + $remaining);
        }

It appears that in some cases, the computed TTL for the lock becomes negative, causing the InvalidTtlException to be thrown.

I am using mariadb:10.6.19

How to reproduce

#[AsSchedule('my')]
final readonly class MyScheduleProvider implements ScheduleProviderInterface
{
    public function __construct(
        private CacheInterface $cache,
        private LockFactory $lockFactory,
    ) {
    }

    public function getSchedule(): Schedule
    {
        return (new Schedule())
            ->stateful($this->cache)
            ->with(RecurringMessage::every(
                frequency: '2 minutes',
                message: new SometimesHeavyProcess(),
                from: new DatePoint('2023-11-10T13:17:55+01:00'),
            ))
            ->lock($this->lockFactory->createLock('my_scheduler'))
        ;
    }
}

SometimesHeavyProcess handling sometimes needs more than 2 minutes to finish (it is quite random, depending on app usage).

Steps to Reproduce:

  1. Configure the scheduler as shown above.
  2. Trigger the scheduler to run (bin/console messenger:consume my_scheduler).
  3. Observe the exceptions thrown due to a negative TTL.

Symfony\Component\Lock\Exception\LockAcquiringException

Failed to define an expiration for the "my_scheduler" lock.

Symfony\Component\Lock\Exception\InvalidTtlException

"Symfony\Component\Lock\Store\DoctrineDbalStore::putOffExpiration()" expects a TTL greater or equals to 1 second. Got "-190.06952309608".

Possible Solution

No response

Additional Context

No response

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

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

No branches or pull requests

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy