Problem/Motivation
Drupal crashes with a segfault when doing a file scan and the the source contains a npm/grunt/nodejs source folder (node_modules). This is probably due to the many folder nesting of npm.
https://drupal.stackexchange.com/questions/126880/how-do-i-prevent-drupa...
Proposed resolution
Ignore the node_modules folder in includes/file.inc
, it has no use for Drupal.
Backport Ignore front end vendor folders to improve directory search performance
Remaining tasks
-
User interface changes
-
API changes
-
Original report by guusvandewal
I use grunt to development templates in plain HTML,
if I clone this HTML source for use in the Drupal templates folder( and run npm install afterwards) it's not possible to clear the cache (with or without drush) anymore.
I get an ' segmentation fault 11 ' error.
A fix would be to hide node_modules from Drupal core in includes/file.inc
I've included a patch.
It would be great if this could be implementated, thanks in advance.
Edit: Proposed change record: https://www.drupal.org/node/3024333
Comment | File | Size | Author |
---|---|---|---|
#80 | 2482549-80-array-syntax.patch | 842 bytes | TR |
#66 | interdiff.txt | 3.52 KB | Pol |
#66 | 2482549.patch | 4.82 KB | Pol |
#38 | core-ignore_node_module-2482549-38.patch | 3.68 KB | jenlampton |
#31 | ignore_node_module-2482549-27.patch | 5.16 KB | marcelovani |
Comments
Comment #1
drupal@guusvandewal.nl CreditAttribution: drupal@guusvandewal.nl commentedComment #2
drupal@guusvandewal.nl CreditAttribution: drupal@guusvandewal.nl commentedComment #3
jeroen.b CreditAttribution: jeroen.b at .VDMi/ commentedComment #5
jeroen.b CreditAttribution: jeroen.b at .VDMi/ commentedComment #6
jeroen.b CreditAttribution: jeroen.b at .VDMi/ commentedPlease provide a proper patch: https://www.drupal.org/node/707484
Comment #7
jeroen.b CreditAttribution: jeroen.b at .VDMi/ commentedComment #8
jeroen.b CreditAttribution: jeroen.b at .VDMi/ commentedDuplicate of #2329453
Comment #9
Fidelix CreditAttribution: Fidelix as a volunteer commented@jeroen.b, that is actually a D8 issue.
This is for D7.
Comment #10
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedIt's marked for Drupal 7 backport, though.
Comment #11
MiSc CreditAttribution: MiSc commentedAdding an reroll here to not confuse the d8 issue.
Comment #12
rooby CreditAttribution: rooby commentedIn light of https://www.drupal.org/node/2715157 I assume this should be reopened and marked as postponed until #2329453: Ignore front end vendor folders to improve directory search performance is fixed?
Comment #13
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedComment #14
rootwork#2329453: Ignore front end vendor folders to improve directory search performance is now fixed.
Comment #15
hussainwebThe patch still applies. Are there any other tasks here?
Comment #16
kaidjohnson CreditAttribution: kaidjohnson commentedThe patch in #11 is incomplete, imo. There are three places where this functionality happens in D7. Also, node_modules isn't enough. bower_components is just as likely to exist (maybe less so now than a year ago), but should be considered a standard front-end module folder.
Migrating final D7 patch (https://www.drupal.org/node/2329453#comment-10622208) from #2329453: Ignore front end vendor folders to improve directory search performance here for review.
Comment #17
RobLoachThis should be hitting a
variable_get('file_scan_ignore_directories');
to retrieve the defaults to keep parity with Drupal 8.Comment #18
ndf CreditAttribution: ndf at Dx Experts commentedComment #19
ndf CreditAttribution: ndf at Dx Experts commentedThe newest drupal 7 patch in #2329453 is https://www.drupal.org/node/2329453#comment-10637754 (#111 not #101).
Added that patch here (2 files are equal):
- ignore_front_end_vendor-2329453-111.patch <-- from #2329453
- ignore_front_end_vendor-2482549-19-7x.patch <-- renamed file
@#17 this patch has the variable_get
Comment #20
ndf CreditAttribution: ndf at Dx Experts commentedComment #21
ndf CreditAttribution: ndf at Dx Experts commentedComment #24
brianV CreditAttribution: brianV as a volunteer commentedBoth the patches in #20 have test runner passes as of Dec 7, 2016 (after they apparently failed). Moving back to CNR.
Comment #25
DamienMcKennaThe tests passed on June 7th, so given this is a backport of functionality already in D8 what's the recommended process to get this committed? Do we need a subsystem maintainer to review?
Comment #26
charginghawk CreditAttribution: charginghawk at Genuine commentedCan confirm that this patch works for me. node_modules is no longer a blight upon my loading times.
Comment #27
marcelovaniIt is not necessary to repeat the following code 3 times in 3 different places
The only place that needs the code above is file_scan_directory() in file.inc.
I will explain why:
If you call file_scan_directory() but you don’t provide the array of options containing ‘nonask’, file_scan_directory() will add it to the $options array, see
We do not need to change the code above. We do not know what side effects we might have by changing the call from drupal_find_theme_templates() to file_scan_directory().
Besides, if you look into drupal_find_theme_templates(), it does a call to file_scan_directory() anyway.
For the same reasons as I explained on part I, if file_scan_directory() gets called without $options[‘nomask’], it will use the default options.
Lastly, for consistency, added the default values to default.settings.php
So the actual patch can be really small.
I am adding a new patch with some tests for it.
The patch will look a lot more similar to what has been done in Drupal 8 on https://www.drupal.org/node/2329453
Comment #29
marcelovaniUnrelated failure
Comment #30
marcelovaniComment #31
marcelovaniRe-submitting the patch
Comment #32
tariqinam CreditAttribution: tariqinam commentedconfirming that #31 patch works as expected.
Comment #33
Leksat CreditAttribution: Leksat at Amazee Labs commentedThe patch works as expected! Looks pretty similar to what we have in D8.
It makes life a lot easier in case if local development uses NFS file sharing and npm is used by some modules/themes.
Comment #34
PolPatch is working fine, thanks, we really need this!
Comment #35
joelpittetComment #36
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedUnless I'm missing something, that's a big difference compared to the Drupal 8 code - Drupal 8 uses an empty array as the default value (and therefore ensures backwards compatibility by not forcing the behavior to change for existing sites; see #2329453-150: Ignore front end vendor folders to improve directory search performance). Why wasn't that done here?
This code will break on PHP 5.2.
I think a simple
foreach ($ignore_directories as &$ignore_directory)
would probably be easier to understand anyway.This looks more complicated than necessary. Is there any reason not to just set
$options['nomask']
in the top code, then not change the bottom code at all? The whole$default_nomask
variable really doesn't seem like it needs to exist.(This suggestion applies to Drupal 8 too, I suppose.)
Comment #37
marcelovaniGood points.
We are using this patch on production on around 16 sites running on PHP 5.6 and the patch works very well.
1. It was assumed that by shipping it with defaults would instantly give the performance benefits to everyone without doing anything. Not all the users follow CHANGELOG to see what is new and what manual steps they need to do. Talking about this, I think we should update the changelog too.
2. Definitely missed that
3. I tried to keep the patch as close as possible to the D8 version, we could change the logic if necessary, but that would require further testings.
Comment #38
jenlampton1) Changed the default to an empty array.
2) I took a stab at this but I'm not sure where
$value
was coming from in the previous patch. +1 to making this bit of code easier to understand.3) Included an attempt to rework this section without
$default_nomask
to make it simpler.Comment #40
jenlamptonPatch in #38 applies cleanly to 7.59, but I'd love some help with the failing tests.
Comment #41
hkirsman CreditAttribution: hkirsman commentedI wasn't noticing anything odd for a year until I installed Lando which is a bit slower on Mac because of virtualisation. admin/config page was loading for about 20-30 seconds. Blamed Lando and Docker and almost gave out.
Luckily first I discovered that there was 3 modules that where not available in file system anymore and this is known to clog the system. For this I found this fix:
I got the speed down to about 10 seconds which was still slow. Did some profiling and found the file_scan_directory() function. It was listing thousands of folders inside one of my custom module I built a year ago - it was the node_modules folder. When I removed that then site/admin folder ran about 2 seconds in Lando. Yay!
My 2 cents for this issue would be to treat node_modules (and bower_components) as importantly as . and CVS folders these days. CVS is probably not as popular even as node_modules is. So why not just hard-code it next to the other folders?
'nomask' => '/(\.\.?|CVS)$/',
vs
'nomask' => '/(\.\.?|CVS|node_modules|bower_components)$/',
I mean nobody would want to have possibility to remove these. 99% would miss the configuration option if it was optional.
Comment #42
drupal@guusvandewal.nl CreditAttribution: drupal@guusvandewal.nl commented3 years later ...
Comment #43
DamienMcKennadrupal@guusvandewal.nl: Instead of passive-aggressively complaining that the problem hasn't been fixed yet, maybe see if you can help resolve the problem, or fund time for someone else to fix it?
Comment #44
drupal@guusvandewal.nl CreditAttribution: drupal@guusvandewal.nl commentedI already gave a solution 3 years ago when I opened this issue, and other people have provided patches as well. I was just wondering why they haven't been implemented.
https://www.psychologytoday.com/us/blog/passive-aggressive-diaries/20170...
Comment #45
marcelovaniWe have been using patch #31 for a year and it works fine, I know that there were some comments and new patches after it, but I did not have time to work on this issue.
All I know is that the patch #31 works for us.
Comment #46
ufku CreditAttribution: ufku commentedHere is a patch that simply makes the nomask regexp a variable.
This doesn't change any functionality and can at least be overridden.
Comment #47
hkirsman CreditAttribution: hkirsman commentedWhat about adding |node_modules|bower_components to the defaults?
Comment #48
PolAt European Commission we are using patch #31 since a long time without any single issue.
I'd like to push it forward, is everyone ok with this ?
Comment #49
PolRefactoring the patch using.
Adressing remarks from @David Rothstein and tests should be green now.
Comment #51
PolUpdating the patch.
Convert new array syntax to old array syntax.
Comment #52
PolComment #54
PolI uploaded the wrong patch, reuploading the proper one.
Comment #56
PolFix patch and tests.
Comment #57
PolUpdate patch, add forgotten staged parts.
Comment #59
marcelovaniCan you please upload the interdiff between your patch and #31
Comment #60
Fabianx CreditAttribution: Fabianx as a volunteer commentedI think a simple loop is easier to read than using array_map here.
if (!empty($ignore_directories)
makes more sense here ...
This will need a change record.
Also:
How was this solved in D8? Is it configurable there?
Comment #61
PolA bit of code tidying and the interdiff.
Comment #62
marcelovani@Fabianx via settings.php https://www.drupal.org/node/2329453
Comment #64
PolUpdated patch based on @fabianx's feedback.
Interdiff with #31 has been uploaded as well.
In Drupal 8, this has been fixed 2 years ago in the same way (see #2329453: Ignore front end vendor folders to improve directory search performance).
Comment #65
Fabianx CreditAttribution: Fabianx as a volunteer commentedThis will need a change record for the new variable in default.settings.php (the one from D8 can likely be copied).
It will also need special attention in release notes
Comment #66
PolUpdated patch, remove "out-of-scope" improvements I introduced and leave only the strict necessary.
Interdiff with #31 included.
Working on the Change Record now.
Comment #67
PolChange record: https://www.drupal.org/node/3024333
Please review it and provides some feedback.
Comment #68
PolComment #69
Fabianx CreditAttribution: Fabianx as a volunteer commentedLooks good now
Comment #74
PolUpdating credits based on this thread and from #2329453: Ignore front end vendor folders to improve directory search performance.
Comment #76
PolComment #78
PolFixed!!!
Thanks everybody !!!
Comment #79
DamienMcKennaComment #80
TR CreditAttribution: TR commentedC'mon guys, you can't use short array syntax in Drupal 7. Whatever happened to testing things before committing?
See https://www.drupal.org/pift-ci-job/1166553
This commit broke ALL PHP 5.3 tests for both core and contrib.
Comment #81
TR CreditAttribution: TR commentedhttps://www.drupal.org/core/issue-priority
Critical bugs include those that:
Comment #82
Liam MorlandPHP 5.3 isn't supported anymore.
Update: My comment is based on what Dries wrote about PHP 5. I note that the PHP requirements page doesn't match this.
In any case, it's not worth breaking compatibility over short array syntax.
Comment #83
TR CreditAttribution: TR commented@Liam Morland: That's a ridiculous and inaccurate claim. Drupal 7 supports PHP >= 5.2.4 and PHP 5.3 tests are a standard part of core and contributed testing. If it weren't for this one little [] instead of array() introduced by the above patch, all these tests would still be running.
Comment #84
markhalliwellInstead of adding fuel to the flames... how about an RTBC?
Comment #85
markhalliwellFTR, 7.62 hasn't been tagged yet... so there's still time.
Great catch @TR.
Comment #86
andypost+1 to commit follow-up fix
Comment #88
PolFixed.
Comment #89
markhalliwell#2581193: [Drupal 7] Require PHP 5.3
Comment #91
xlin CreditAttribution: xlin as a volunteer commentedThis commit seems change the default.settings.php permission from 644 to 755. Anyone know why that is the case?
Comment #92
Liam MorlandI don't see anything in this commit that would touch default.settings.php at all. It must be something else.
Comment #93
jacob.embree CreditAttribution: jacob.embree commentedhttps://www.drupal.org/project/drupal/issues/2482549#comment-12917581
This one did it.
Comment #94
jacob.embree CreditAttribution: jacob.embree commentedThanks, Pol. #3035772: [Regression] Fix default.settings.php permission fixed the file permissions.