Repository: symfony/symfony
File: src/Symfony/Component/Messenger/Bridge/Doctrine/EventListener/PostgreSqlNotifyOnIdleListener.php (PHP)

Code before:

        // Cap by earliest delayed message: wake up in time to process it
        if (null !== $earliest = $this->activeConnection->getEarliestDelayedMessageTime()) {
            $now = $this->clock->now();
            $deadline = ($earliest->format('U.u') - $now->format('U.u')) * 1000;
            if (0 >= $timeout = min($timeout, $deadline)) {
                return;
            }
        }

        // Cap by worker deadline (--time-limit)
        if (null !== $this->deadline) {
            $deadline = ($this->deadline - $this->clock->now()->format('U.u')) * 1000;
            if (0 >= $timeout = min($timeout, $deadline)) {
                return;
            }
        }

        // Cap by sleep duration when non-PG transports are present to ensure they are still polled regularly
        if (0 >= $timeout = min($timeout, $this->sleepCapMs ?? $timeout)) {
            return;
        }

        $this->logger?->debug('Worker waiting for PostgreSQL LISTEN/NOTIFY wake-up.', ['timeout_ms' => $timeout]);

        $this->activeConnection->waitForNotify((int) $timeout);
    }

    public static function getSubscribedEvents(): array
    {
        return [
            WorkerStartedEvent::class => 'onWorkerStarted',
            WorkerRunningEvent::class => 'onWorkerRunning',
        ];
    }

    /**
     * @param array<string, PostgreSqlConnection> $connections
     */
    private function validateConnections(array $connections): void
    {
        $referenceConfig = null;
        $referenceDriver = null;
        $referenceName = null;

        foreach ($connections as $transportName => $connection) {
            $config = $connection->getConfiguration();
            $driver = $connection->getDriverConnection();

            if (null === $referenceConfig) {
                $referenceConfig = $config;

Review comment (suggestion):
I'm worried about this int-cast. It could potentially cast a float like `0.3` to int `0`, and feed that zero to `waitForNotify()`. I believe that passing zero there, would result in disabling the `timeout`, which isn't correct. 

Just for safety (and sanity), could an additional check be added here that the `(int) $timeout` is not 0, and if it is , then it should just `return;` (i.e. not invoke the `waitForNotify()`)

Code after:
            return;
        }

        // Cap by worker deadline (--time-limit) — checked first to avoid a SQL query
        // in getEarliestDelayedMessageTime() when the worker is already past its deadline.
        if (null !== $this->deadline) {
            $deadline = ($this->deadline - $this->clock->now()->format('U.u')) * 1000;
            if (0 >= $timeout = min($timeout, $deadline)) {
                return;
            }
        }

        // Cap by earliest delayed message across all PG queues: wake up in time to process it
        if (null !== $earliest = $this->getEarliestDelayedMessageTime()) {
            $now = $this->clock->now();
            $msUntilEarliest = ($earliest->format('U.u') - $now->format('U.u')) * 1000;
            if (0 >= $timeout = min($timeout, $msUntilEarliest)) {
                return;
            }
        }

        // Cap by sleep duration when non-PG transports are present to ensure they are still polled regularly
        if (0 >= $timeout = (int) min($timeout, $this->sleepCapMs ?? $timeout)) {
            return;
        }

        $this->logger?->debug('Worker waiting for PostgreSQL LISTEN/NOTIFY wake-up.', ['timeout_ms' => $timeout]);

        $this->activeConnection->waitForNotify($timeout);
    }

    public static function getSubscribedEvents(): array
    {
        return [
            WorkerStartedEvent::class => 'onWorkerStarted',
            WorkerRunningEvent::class => 'onWorkerRunning',
        ];
    }

    /**
     * @param array<string, PostgreSqlConnection> $connections
     */
    private function validateConnections(array $connections): void
    {
        $referenceConfig = null;
        $referenceDriver = null;
        $referenceName = null;

        foreach ($connections as $transportName => $connection) {
            $config = $connection->getConfiguration();
            $driver = $connection->getDriverConnection();