Skip to content

Container lock file not released when container build fails #60113

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

Closed
3amprogrammer opened this issue Apr 1, 2025 · 2 comments
Closed

Container lock file not released when container build fails #60113

3amprogrammer opened this issue Apr 1, 2025 · 2 comments

Comments

@3amprogrammer
Copy link

3amprogrammer commented Apr 1, 2025

Symfony version(s) affected

7.1

Description

When the container fails to build (e.g. due to misconfigured services), Symfony does not release the lock created here. This causes subsequent calls to bootKernel() (e.g., in a test suite running multiple tests) to freeze indefinitely on flock().

Steps to Reproduce

  1. Create a misconfigured service (e.g. missing required constructor argument).
  2. Create a PHPUnit test with at least 2 test cases and a setup method that boots the kernel.
  3. Run tests.
  4. Watch it freeze on the second test case setUp method.

Actual Behaviour
The first test's setUp method is executed and bootKernel is called, it throws as expected because of misconfigured service, but the .lock file is not released.

The second test's hangs indefinitely while trying to acquire the lock.

No cleanup happens when the exception is thrown.

Expected Behaviour
The .lock file should be released when compiling the container fails, to prevent deadlocks or the tests should fail immediately.

Relevant file
Kernel.php

How to reproduce

  1. Clone the repository and install dependencies.
  2. Observe the misconfigured PostRepository service (missing constructor call).
  3. Run tests: bin/phpunit tests/ExampleTest.php

Temporal work around

class TestKernel extends BaseKernel
{
    /**
     * @throws Throwable
     */
    protected function initializeContainer(): void
    {
        try {
            parent::initializeContainer();
        } catch (Throwable $e) {
            $class     = $this->getContainerClass();
            $buildDir  = $this->getBuildDir();
            $cache     = new ConfigCache($buildDir . '/' . $class . '.php', $this->debug);
            $cachePath = $cache->getPath() . '.lock';

            @unlink($cachePath);

            throw $e;
        }
    }
}
@MatTheCat
Copy link
Contributor

I couldn’t reproduce using PHP 8.4.5 on Ubuntu 22.04. If the behavior you observe is tied to your environment it would be good to add a corresponding Dockerfile to the repository.

@xabbuh
Copy link
Member

xabbuh commented Apr 23, 2025

I am going to close here for now due to the lack of feedback. Please let us know when you have more information and we can consider to reopen.

@xabbuh xabbuh closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2025
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

4 participants