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

Segmentation fault when compiling susy #1879

Closed
IlyaSemenov opened this issue Feb 1, 2017 · 23 comments
Closed

Segmentation fault when compiling susy #1879

IlyaSemenov opened this issue Feb 1, 2017 · 23 comments

Comments

@IlyaSemenov
Copy link

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 node-sass@4.5.0 susy@2.2.12
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):
    /
    `-- node-sass@4.5.0
@xzyfer
Copy link
Contributor

xzyfer commented Feb 1, 2017

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
Copy link
Contributor

xzyfer commented Feb 1, 2017

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

@m4rcelofs
Copy link

Also happens in the node:7.4.0-alpine image.

@nizhu
Copy link

nizhu commented Feb 2, 2017

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

@xzyfer
Copy link
Contributor

xzyfer commented Feb 2, 2017

@m4rcelofs @nizhu are you both using alpine?

@nizhu
Copy link

nizhu commented Feb 2, 2017

@xzyfer yes! 3.3.1

@xzyfer
Copy link
Contributor

xzyfer commented Feb 6, 2017

I've narrow this down a bug with LibSass introduced in sass/libsass@6a5444b (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
Copy link
Contributor

xzyfer commented Feb 6, 2017

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
Copy link
Contributor

xzyfer commented Feb 6, 2017

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.

@mgreter
Copy link
Contributor

mgreter commented Feb 6, 2017

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 node-sass@4.5.0 susy@2.2.12
 ---> 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!

@xzyfer
Copy link
Contributor

xzyfer commented Feb 6, 2017

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 node-sass@4.3.0 susy@^2
RUN gcc -v
RUN node node_modules/.bin/node-sass node_modules/susy/sass/_susy.scss

@mgreter
Copy link
Contributor

mgreter commented Feb 6, 2017

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 node-sass@4.3.0 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
...

@xzyfer
Copy link
Contributor

xzyfer commented Feb 6, 2017

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
Copy link
Contributor

xzyfer commented Feb 7, 2017

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

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

@xzyfer
Copy link
Contributor

xzyfer commented Feb 7, 2017

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

@xzyfer
Copy link
Contributor

xzyfer commented Feb 7, 2017

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.

@lucaperret
Copy link

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

@xzyfer
Copy link
Contributor

xzyfer commented Jun 17, 2017

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

@franknoel
Copy link

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

@xzyfer
Copy link
Contributor

xzyfer commented Jul 4, 2017

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

@cw789
Copy link

cw789 commented Feb 9, 2018

Kind of fix could possibly be the following addition in your Dockerfiles.
Fix: nodejs/docker-node#588

@IlyaSemenov
Copy link
Author

Interestingly enough but the original Dockerfile that I included in the issue description above doesn't crash for me any longer: https://gist.github.com/IlyaSemenov/88bc27acdd4131aabd7bba901940d7a7

Same goes to the minimal reproduction (https://github.com/xzyfer/node-sass-1879), it runs fine.

I believe the issue may be closed as outdated?

@nschonni
Copy link
Contributor

@IlyaSemenov thanks for reporting back ❤️

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

9 participants