Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Segfault when compilation raises errors #1858

Closed
richardsimko opened this issue Jan 13, 2017 · 7 comments
Closed

Segfault when compilation raises errors #1858

richardsimko opened this issue Jan 13, 2017 · 7 comments

Comments

@richardsimko
Copy link

richardsimko commented Jan 13, 2017

A part of our SASS code generates segfaults when compiled with node-sass (I'm using grunt-sass for the compilation) in case something goes wrong with the compilation. I've tried to figure out what may be causing it but I'm really drawing a blank here, so perhaps someone with better insight into node-sass or libsass can help me out.

I have an example repo here in which I've cut down as much of the code as possible: https://github.com/richardsimko/sass-segfault

Running grunt sass after checking out and installing will crash with a segfault.

I have found the following clues:

  1. If there are no errors (In this case there is an import to a file that does not exist) then it all compiles fine, as such the CSS should be fine.
  2. Removing all CSS code from the file _organizer.scss fixes the issue (I.e. a proper exit without segfaults even on error)
  3. Removing some of the code from _organizer.scss causes the error to become infrequent, for example removing approximately 100 lines causes it to only happen about 1/4 of the times
  4. Errors in the file admin.scss does not cause the problem (Uncomment the line that says //@import 'uncomment me to test not found here'; to test)
  5. We're tried this on a number of different machines with the same result, however they were all Mac environments so I'm hoping for someone else to be able to test and duplicate it
  6. I've seen a few tickets related to segfaults in libsass previously but they've all been fixed
  7. It may be related to the variables, removing all references to variables in _organizer.scss also fixes the issue
  8. The files are syntactically correct, moving all the variables from _config.scss into _organizer.scss and running it using https://www.sassmeister.com/ provides a clean compilation
  9. Removing about 10 or so of the unused variables also fixes the segfault issue

Output

bash-3.2$ grunt sass
Running "sass:test" (sass) task
>> Error: File to import not found or unreadable: intentionally not found.
>>        Parent style sheet: /Users/richard/Desktop/Refined Wiki/temp/sass-test/test/modules.scss
>>         on line 2 of test/modules.scss
>> >> @import 'intentionally not found';
>>    ^
Warning:  Use --force to continue.

Aborted due to warnings.
Segmentation fault: 11

Environment Info

  • NPM version (npm -v): 4.1.1

  • Node version (node -v): 4.7.0

  • Node Process (node -p process.versions):

      { http_parser: '2.7.0',
      node: '4.7.0',
      v8: '4.5.103.43',
      uv: '1.9.1',
      zlib: '1.2.8',
      ares: '1.10.1-DEV',
      icu: '56.1',
      modules: '46',
      openssl: '1.0.2j' }
    
  • Node Platform (node -p process.platform): darwin

  • Node architecture (node -p process.arch): x64

  • node-sass version (node -p "require('node-sass').info"):

      node-sass       4.3.0   (Wrapper)       [JavaScript]
      libsass         3.4.3   (Sass Compiler) [C/C++]
    
  • npm node-sass versions (npm ls node-sass):

npm ls node-sass:

@richardsimko
Copy link
Author

I have reproduced this on a machine running Ubuntu as well with the following environment:

npm -v: 3.8.6
node -v: 4.4.3
node -p process.versions:

{ http_parser: '2.5.2',
node: '4.4.3',
v8: '4.5.103.35',
uv: '1.8.0',
zlib: '1.2.8',
ares: '1.10.1-DEV',
icu: '56.1',
modules: '46',
openssl: '1.0.2g' }

node -p process.platform: linux
node -p process.arch: x64
node -p "require('node-sass').info")

node-sass	4.3.0	(Wrapper)	[JavaScript]
libsass  	3.4.3	(Sass Compiler)	[C/C++]

npm ls node-sass: Same as above, I used the same example project.

Output:

$ grunt sass
Running "sass:test" (sass) task
>> Error: File to import not found or unreadable: intentionally not found.
>>        Parent style sheet: /home/1-bamboo-agent/temp-richard/sass-segfault/test/modules.scss
>>         on line 2 of test/modules.scss
>> >> @import 'intentionally not found';
>>    ^
Warning:  Use --force to continue.

Aborted due to warnings.
Segmentation fault

@xzyfer
Copy link
Contributor

xzyfer commented Mar 6, 2017

This may be related to #1879. I wasn't able to reproduce on Darwin or Linux with the reproduction #1879. I see if I can also reproduce on Darwin with this reproduction.

Have you tried with a newer version of node-sass?

@richardsimko
Copy link
Author

Just tried it, I'm afraid my example repo still causes the issue and same goes for our production code. Like you mention in the other issue, there are a number of parts at play and it's really hard to narrow it down to what exactly seems to cause it.

Note that it only happens if the compilation fails, it also seems to happen more often with a larger code base (As in our production case). If I remove a sufficient amount of random CSS from the example repo it stops happening and the compilation exits as it should on error.

@Shamir786
Copy link

We are facing a similar kind of issue,

Where as the SASS file in our production code generates 1 CSS file with combined set of CSS files. when we run the product styles from here and there breaks. but when we remove or comment a random set of SASS code and compile the CSS file then it generates fine and no style issues occur.

Any clue why this may be happening?

@nschonni
Copy link
Contributor

nschonni commented Jul 14, 2017

I see the warning but not the segfault running 4.5.3 on OSX

Nicks-MacBook-Pro:sass-segfault nschonni$ grunt sass
Running "sass:test" (sass) task
>> Error: File to import not found or unreadable: intentionally not found.
>>        Parent style sheet: /Users/nschonni/Documents/github/sass-segfault/test/modules.scss
>>         on line 2 of test/modules.scss
>> >> @import 'intentionally not found';
>>    ^
Warning:  Use --force to continue.

Aborted due to warnings.

Edit: this is under Node 8 though

[email protected] /Users/nschonni/Documents/github/sass-segfault
└─┬ [email protected]
  └── [email protected] 

@richardsimko
Copy link
Author

richardsimko commented Jul 14, 2017

Under node 6.11.1 I'm still seeing the segfault

☿ grunt sass                                                                                                                                                        07/14/17 08:38:23 CEST
Running "sass:test" (sass) task
>> Error: File to import not found or unreadable: intentionally not found.
>>        Parent style sheet: /Users/richard/Desktop/git/sass-segfault/test/modules.scss
>>         on line 2 of test/modules.scss
>> >> @import 'intentionally not found';
>>    ^
Warning:  Use --force to continue.

Aborted due to warnings.
[1]    10760 segmentation fault  grunt sass

Same dependency versions as you

[email protected] /Users/richard/Desktop/git/sass-segfault
└─┬ [email protected]
  └── [email protected]

However like you say Node 8 seems to fix it for me as well.

@xzyfer
Copy link
Contributor

xzyfer commented Mar 10, 2018

This is probably fixed in 4.8.0

@xzyfer xzyfer closed this as completed Mar 10, 2018
jiongle1 pushed a commit to scantist-ossops-m2/node-sass that referenced this issue Apr 7, 2024
…isitor

Remove `To_String` by using `AST->to_string` and `inspect`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants