node-sass icon indicating copy to clipboard operation
node-sass copied to clipboard

Segmentation fault when compiling susy

Open IlyaSemenov opened this issue 9 years ago • 23 comments

node-sass 4.5.0 (and 4.4.0) fails to compile susy 2.2.12 with a segfault.

Steps to reproduce:

  1. Create a Dockerfile:
FROM alpine:3.5
RUN apk add --no-cache nodejs
RUN npm i [email protected] [email protected]
RUN node_modules/.bin/node-sass  node_modules/susy/sass/_susy.scss
  1. Run it:
$ docker build .
...
Step 4/4 : RUN node_modules/.bin/node-sass  node_modules/susy/sass/_susy.scss
 ---> Running in a20e432a5a46
Segmentation fault
The command '/bin/sh -c node_modules/.bin/node-sass  node_modules/susy/sass/_susy.scss' returned a non-zero code: 139

If you replace node-sass version with 4.3.0 it compiles fine. Also, I didn't manage to repeat this on Ubuntu so it might be Alpine Linux-specific.

Please note that I deliberately trimmed the example. Of course there's no point to compile susy from command line in real world. But it crashes the same way in full webpack environment as well.

  • NPM version (npm -v): 3.10.9
  • Node version (node -v): v6.9.2
  • Node Process (node -p process.versions): { http_parser: '2.7.1', node: '6.9.2', v8: '5.1.281.88', uv: '1.9.1', zlib: '1.2.8', ares: '1.10.1-DEV', icu: '57.1', modules: '48', openssl: '1.0.2j' }
  • Node Platform (node -p process.platform): linux
  • Node architecture (node -p process.arch): x64
  • node-sass version (node -p "require('node-sass').info"): node-sass 4.5.0 (Wrapper) [JavaScript] libsass 3.5.0.beta.2 (Sass Compiler) [C/C++]
  • npm node-sass versions (npm ls node-sass): / `-- [email protected]

IlyaSemenov avatar Feb 01 '17 09:02 IlyaSemenov

Thanks for the report. I have been able to reproduce this issue on the alpine:3.5 image and the node:6-alpine image which is the image we use to build our binaries.

I was not able to reproduce the issue on OSX. Still investigating.

xzyfer avatar Feb 01 '17 10:02 xzyfer

Interestingly even building fresh binaries on Alpine produces the segfault which is interesting.

xzyfer avatar Feb 01 '17 10:02 xzyfer

Also happens in the node:7.4.0-alpine image.

m4rcelofs avatar Feb 01 '17 17:02 m4rcelofs

Also getting segfaults on node-sass 4.4/4.5 on node 4.3.0, still trying to reproduce with a smaller piece of code though

nizhu avatar Feb 02 '17 00:02 nizhu

@m4rcelofs @nizhu are you both using alpine?

xzyfer avatar Feb 02 '17 01:02 xzyfer

@xzyfer yes! 3.3.1

nizhu avatar Feb 02 '17 02:02 nizhu

I've narrow this down a bug with LibSass introduced in https://github.com/sass/libsass/commit/6a5444b2e7420b79fb53da4afec05db524c1b3ef (be warned the diff may crash your browser).

I've been able to reproduce this on Alpine, but not OSX. I have also been able to confirm the issue doesn't appear when compiled with -O0, which suggests some compiler optimisations is either surfacing or trigging an issue. I've tried a couple different compilers version without any luck. The compiler available on the offical Node Alpine images is much newer than the one we use in CI.

This is as far as I've gotten at the moment.

xzyfer avatar Feb 06 '17 08:02 xzyfer

For posterity

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-alpine-linux-musl/5.3.0/lto-wrapper
Target: x86_64-alpine-linux-musl
Configured with: /home/buildozer/aports/main/gcc/src/gcc-5.3.0/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=x86_64-alpine-linux-musl --host=x86_64-alpine-linux-musl --target=x86_64-alpine-linux-musl --with-pkgversion='Alpine 5.3.0' --enable-checking=release --disable-fixed-point --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --disable-symvers --enable-__cxa_atexit --enable-esp --enable-cloog-backend --enable-languages=c,c++,objc,java,fortran,ada --disable-libssp --disable-libmudflap --disable-libsanitizer --enable-shared --enable-threads --enable-tls --with-system-zlib
Thread model: posix
gcc version 5.3.0 (Alpine 5.3.0)

xzyfer avatar Feb 06 '17 08:02 xzyfer

I can confirm the rebuild the binary locally with CXXFLAGS='-O0' is a work aroun. I'll regenerate the official binaries with -O0 until we have a solution.

xzyfer avatar Feb 06 '17 09:02 xzyfer

FWIW. I cannot reproduce on my virtual box machine:

Sending build context to Docker daemon 2.048 kB
Step 1 : FROM alpine:3.5
 ---> 88e169ea8f46
Step 2 : RUN apk add --no-cache nodejs
 ---> Using cache
 ---> 2bcb7a77c8ae
Step 3 : RUN npm i [email protected] [email protected]
 ---> Using cache
 ---> d0ac5f8558eb
Step 4 : RUN node_modules/.bin/node-sass  node_modules/susy/sass/_susy.scss
 ---> Running in 9fb86a30d241
 ---> 78ebbd314871
Removing intermediate container 9fb86a30d241
Successfully built 78ebbd314871

Note that -O0 might be terribly slow!

mgreter avatar Feb 06 '17 11:02 mgreter

I've just uploaded the -O0 binaries so you wont be able to reproduce the error like that. This is how I reproduce it.

FROM node:6-alpine
RUN apk add --update --no-cache nodejs python=2.7.12-r0 git-perl bash make gcc g++
RUN npm install susy@^2
SKIP_SASS_BINARY_DOWNLOAD_FOR_CI=true npm install [email protected] susy@^2
RUN gcc -v
RUN node node_modules/.bin/node-sass node_modules/susy/sass/_susy.scss

xzyfer avatar Feb 06 '17 11:02 xzyfer

I was able to reproduce with node-sass but not with any other code base (latest perl-libsass dev branch and sassc). @xzyfer have you tried latest mater with node-sass? .

RUN apk add --update --no-cache nodejs python=2.7.12-r0 git-perl perl-dev bash make gcc g++
RUN npm install susy@^2
ENV SKIP_SASS_BINARY_DOWNLOAD_FOR_CI=true
RUN npm install [email protected] susy@^2
RUN gcc -v
RUN git clone https://github.com/sass/libsass && cd libsass && git clone https://github.com/sass/sassc && cd sassc && make -j8
RUN libsass/sassc/bin/sassc node_modules/susy/sass/_susy.scss > susy.sassc.css
RUN perl -MCPAN -e "CPAN::Shell->rematein('notest', 'install', 'File::Slurp')"
RUN perl -MCPAN -e "CPAN::Shell->rematein('notest', 'install', 'List::MoreUtils')"
RUN perl -MCPAN -e "CPAN::Shell->rematein('notest', 'install', 'Encode::Locale')"
RUN perl -MCPAN -e "CPAN::Shell->rematein('notest', 'install', 'ExtUtils::CppGuess')"
RUN git clone https://github.com/sass/perl-libsass && cd perl-libsass && perl Makefile.PL --no-plugins && make -j8 install
RUN psass node_modules/susy/sass/_susy.scss
RUN ulimit -c unlimited && node node_modules/.bin/node-sass node_modules/susy/sass/_susy.scss || ls

Took me some time to figure out since it's the first time I'm actually using docker. Not that easy to figure out how to attach to an image when your new. Anyway, after a while I got a bash prompt and was able to debug the core dump.

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f7a99407958 in Sass::Parser::parse_arguments() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#0  0x00007f7a99407958 in Sass::Parser::parse_arguments() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#1  0x00007f7a99408c39 in Sass::Parser::parse_function_call() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#2  0x00007f7a99400422 in Sass::Parser::parse_factor() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#3  0x00007f7a99400aca in Sass::Parser::parse_operators() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#4  0x00007f7a994013ba in Sass::Parser::parse_expression() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#5  0x00007f7a9940263a in Sass::Parser::parse_relation() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#6  0x00007f7a9940378a in Sass::Parser::parse_conjunction() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#7  0x00007f7a994040ea in Sass::Parser::parse_disjunction() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#8  0x00007f7a99404980 in Sass::Parser::parse_space_list() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#9  0x00007f7a99406bd4 in Sass::Parser::parse_argument() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#10 0x00007f7a99407d9f in Sass::Parser::parse_arguments() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#11 0x00007f7a99408c39 in Sass::Parser::parse_function_call() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#12 0x00007f7a99400422 in Sass::Parser::parse_factor() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#13 0x00007f7a99400aca in Sass::Parser::parse_operators() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#14 0x00007f7a994013ba in Sass::Parser::parse_expression() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#15 0x00007f7a9940263a in Sass::Parser::parse_relation() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#16 0x00007f7a9940378a in Sass::Parser::parse_conjunction() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#17 0x00007f7a994040ea in Sass::Parser::parse_disjunction() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#18 0x00007f7a99404980 in Sass::Parser::parse_space_list() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#19 0x00007f7a993e6859 in Sass::Parser::parse_comma_list(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#20 0x00007f7a993e7213 in Sass::Parser::parse_list(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#21 0x00007f7a9940ab5c in Sass::Parser::parse_assignment() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#22 0x00007f7a9941411c in Sass::Parser::parse_block_node(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#23 0x00007f7a99417ac3 in Sass::Parser::parse_block_nodes(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#24 0x00007f7a99418bdd in Sass::Parser::parse_css_block(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#25 0x00007f7a99419748 in Sass::Parser::parse_block(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#26 0x00007f7a9941cc0d in Sass::Parser::parse_each_directive() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#27 0x00007f7a9941589d in Sass::Parser::parse_block_node(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#28 0x00007f7a99417ac3 in Sass::Parser::parse_block_nodes(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#29 0x00007f7a99418bdd in Sass::Parser::parse_css_block(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#30 0x00007f7a99419748 in Sass::Parser::parse_block(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#31 0x00007f7a9941cc0d in Sass::Parser::parse_each_directive() () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#32 0x00007f7a9941589d in Sass::Parser::parse_block_node(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#33 0x00007f7a99417ac3 in Sass::Parser::parse_block_nodes(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#34 0x00007f7a99418bdd in Sass::Parser::parse_css_block(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#35 0x00007f7a99419748 in Sass::Parser::parse_block(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#36 0x00007f7a9941acee in Sass::Parser::parse_if_directive(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#37 0x00007f7a99414c64 in Sass::Parser::parse_block_node(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#38 0x00007f7a99417ac3 in Sass::Parser::parse_block_nodes(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#39 0x00007f7a99418bdd in Sass::Parser::parse_css_block(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
#40 0x00007f7a99419748 in Sass::Parser::parse_block(bool) () from /node_modules/node-sass/vendor/linux_musl-x64-48/binding.node
...

mgreter avatar Feb 06 '17 22:02 mgreter

Thanks for following up in this. I was also unable to reproduce it with SassC. I hadn't had time to get a core dump, thanks.

@xzyfer have you tried latest mater with node-sass?

I have not. I've been working on patch for a couple nullptr and memory leaks which I'd hoped might address this issue.

I'll keep looking into this and that PR so we can update node-sass' LibSass. I know CodeKit is currently blocked on 3.5.0.beta.3 which I've been delaying until this could be sorted out.

xzyfer avatar Feb 06 '17 23:02 xzyfer

I wasn't able to build the clang static analyzer on Alpine.

I can confirm the issue is still present using LibSass master.

xzyfer avatar Feb 07 '17 10:02 xzyfer

I have a minimal reproduction at https://github.com/xzyfer/node-sass-1879

xzyfer avatar Feb 07 '17 13:02 xzyfer

This could maybe be cut down a little bit more. It's late here so I'll continue looking at it tomorrow.

Interestingly there are a lot of elements in play, including @import, required to trigger this issue.

xzyfer avatar Feb 07 '17 13:02 xzyfer

Hi @xzyfer, do you have found a work around ?

lucaperret avatar Jun 12 '17 18:06 lucaperret

No work around. Might be fixed with newer alpines images but I haven't had a chance to test.

xzyfer avatar Jun 17 '17 00:06 xzyfer

Is there any Alpine version that does not have this issue?

franknoel avatar Jul 03 '17 19:07 franknoel

I don't know. We welcome people testing and reporting back.

xzyfer avatar Jul 04 '17 01:07 xzyfer