Skip to content
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

Fix #207: Allow multiple instances of drupal-check to run #208

Closed
wants to merge 2 commits into from

Conversation

manarth
Copy link

@manarth manarth commented Feb 15, 2021

Fixes #207

Include the PHP process ID in the temporary configuration filename, so that two instances of drupal-check starting simultaneously do not share the same configuration file.

Include the process ID in the temporary configuration filename, so that two instances of drupal-check starting simultaneously do not share the same configuration file.
If two phpstan processes share the same temp directory, it reports "PHPStan crashed in the previous run probably because of excessive memory consumption."
@prudloff-insite
Copy link

prudloff-insite commented Mar 15, 2021

This patch fixed the unlink() issue for us.
However, the cache folder is never deleted and it contains a lot of files, so if you run drupal-check a lot, you should take care of clearing /tmp/ or you might run out of inodes.

@mglaman
Copy link
Owner

mglaman commented Mar 17, 2021

Interesting. This sounds like it should also affect phpstan in general. I'll see how they generate the tmpDir. Because we should fix this upstream

@mglaman
Copy link
Owner

mglaman commented Mar 17, 2021

So it doesn't handle it there either: https://github.com/phpstan/phpstan-src/blob/a1c7572a7be6251f2ef2265a97c75a26427f8741/src/Command/CommandHelper.php#L244

		if (!isset($tmpDir)) {
			$tmpDir = sys_get_temp_dir() . '/phpstan';
			$createDir($tmpDir);
		}

We should make sure to create a follow up there.

@mglaman
Copy link
Owner

mglaman commented Mar 17, 2021

Sorry, I'm wrong. I realize this is about the custom configuration generated when running drupal-check and its clean up. Not the caches and such made by PHPStan

Copy link
Owner

@mglaman mglaman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is something we should be adding as I'm afraid of consequences. Also, PHPStan doesn't do this when generating its temp directory.

If the problems is Jenkins sharing temp directories, each job is not isolated enough. I would override the PHP ini value that sets the system temp directory.

sys_temp_dir = "/var/tmp"

See https://www.php.net/manual/en/ini.list.php

Maybe we could add an option for specifying the temp directory. Otherwise, I highly recommend just adding phpstan/phpstan with mglaman/phpstan-drupal to your project and customizing the config directly there.

Comment on lines +142 to +143
],
'tmpDir' => sys_get_temp_dir() . '/phpstan' . '_' . getmypid(),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we should be modifying the tmpDir where PHPStan puts its caches. If this is having issues in Jenkins on a shared environment, is there a way to customize the system temp directory PHP pulls?

@prudloff-insite
Copy link

Thanks for having a look at this.

I agree that our CI is not isolated enough (and as a workaround we ended up having a cron job to clean the /tmp/phpstan_* folders).
We were just a bit surprised when we started running out of inodes after applying this patch because our /tmp/ folder was full of phpstan_15415/, phpstan_15890/, etc.

When using phpstan directly (or drupal-check without this patch), this is not a problem because the folder is always /tmp/phpstan/ and is reused by each run.
With this patch, the folder is different for every process so it does not make a lot of sense to keep it after the run because it will never be reused (unless another uses the same PID but it should not happen often).

@uberhacker
Copy link

To say the temp folder uses a lot of space is an understatement. I ran this twice on 2 different D8 and D9 sites and the result was below:

$ du -hs /tmp/phpstan/
939M    /tmp/phpstan/

Seriously? Rather than changing the folder name, would it make sense to create subdirectories with the pid instead? Something like /tmp/phpstan/123, /tmp/phpstan/234, etc. That way simply runningrm -rf /tmp/phpstan would clear everything out.

@mglaman
Copy link
Owner

mglaman commented Feb 2, 2022

If you have these problems, use PHPStan directly and customize the tmpDir. I'm not going to rebuild features in PHPStan for this tool.

@mglaman mglaman closed this Feb 2, 2022
@prudloff-insite
Copy link

An easy workaround is to use the TMPDIR environment variable:

TMPDIR=./foo/ ./vendor/bin/drupal-check

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

Successfully merging this pull request may close these issues.

Drupal-check reports errors when running multiple instances
4 participants