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

Segmentation fault on Node 8 alpine (docker) #2031

Closed
ForsakenHarmony opened this issue Jun 27, 2017 · 48 comments
Closed

Segmentation fault on Node 8 alpine (docker) #2031

ForsakenHarmony opened this issue Jun 27, 2017 · 48 comments

Comments

@ForsakenHarmony
Copy link

Works with node 6 and on my host machine ( debian, node 8 )

this is my project, can also try to make a smaller testcase if required
https://github.com/ForsakenHarmony/portfolio

yarn build v0.24.6                                                                                                  
$ cross-env NODE_ENV=production npm run webpack                                                                     
npm info it worked if it ends with ok                                                                               
npm info using npm@5.0.3                                                                                            
npm info using node@v8.1.2                                                                                          
npm info lifecycle portfolio@0.1.0~prewebpack: portfolio@0.1.0                                                      
npm info lifecycle portfolio@0.1.0~webpack: portfolio@0.1.0                                                         
                                                                                                                    
> portfolio@0.1.0 webpack /usr/src/app                                                                              
> webpack --progress --colors --config webpack.config.js                                                            
                                                                                                                    
 12% building modules 20/21 modules 1 active ...!/usr/src/app/client/styles/main.scssSegmentation fault (core dumped
)                                                                                                                   
npm info lifecycle portfolio@0.1.0~webpack: Failed to exec webpack script                                           
npm ERR! code ELIFECYCLE                                                                                            
npm ERR! errno 139                                                                                                  
npm ERR! portfolio@0.1.0 webpack: `webpack --progress --colors --config webpack.config.js`                          
npm ERR! Exit status 139                                                                                            
npm ERR!                                                                                                            
npm ERR! Failed at the portfolio@0.1.0 webpack script.                                                              
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.                  
                                                                                                                    
npm ERR! A complete log of this run can be found in:                                                                
npm ERR!     /root/.npm/_logs/2017-06-26T22_44_11_188Z-debug.log                                                    
error Command failed with exit code 139.                                                                            
Removing intermediate container 5cb53913df5e
  • NPM version (npm -v):
    5.0.3
  • Node version (node -v):
    v8.1.2
  • Node Process (node -p process.versions):
    { http_parser: '2.7.0',
    node: '8.1.2',
    v8: '5.8.283.41',
    uv: '1.12.0',
    zlib: '1.2.11',
    ares: '1.10.1-DEV',
    modules: '57',
    openssl: '1.0.2l',
    icu: '59.1',
    unicode: '9.0',
    cldr: '31.0.1',
    tz: '2017b' }
  • 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.3 (Wrapper) [JavaScript]
    libsass 3.5.0.beta.2 (Sass Compiler) [C/C++]
@nschonni
Copy link
Contributor

Can you add the log to a Gist? I'm not seeing anything in the current output, besides that it failed around a Sass file, that indicates this is a node-sass issue.

I'd also suggest just trying to reproduce it without webpack

@ForsakenHarmony
Copy link
Author

https://gist.github.com/ForsakenHarmony/3ddcfcab7e932a5a6a48094eda7854c7

I'm not quite sure what's going on, it only seems to happen in the docker build script, not if I run it inside the container

may also be my code, because this doesn't crash

FROM node:8-alpine

RUN mkdir -p /usr/app
WORKDIR /usr/app

RUN yarn add node-sass
ENV NODE_ENV production
RUN node -e "require('node-sass').renderSync({data: '* {height: 2px}'});"

@saper
Copy link
Member

saper commented Jun 28, 2017

It does not seem to crash. Looks like a permission problem, people usually run as root inside a container, check our troubleshooting guide for info on unsafe permissions

@ForsakenHarmony
Copy link
Author

Segmentation fault is a type of crash to me

@saper
Copy link
Member

saper commented Jun 28, 2017

I am sorry, didn't scroll that far right. Can you try to get the core file?

@saper
Copy link
Member

saper commented Jun 28, 2017

Quick question, are project files copied from Debian?

@xzyfer
Copy link
Contributor

xzyfer commented Jun 30, 2017

You'll need to delete your node_modules and reinstall your modules inside the container. Copying files from (or reusing a cache) between debian and alpine is going to result in segfaults.

@ForsakenHarmony
Copy link
Author

@saper the core file?
also yes, copied from debian
node_modules doesn't get copied ( doesn't exist )
I get the feeling it's the build itself

@saper
Copy link
Member

saper commented Jun 30, 2017

probably your binding.node is copied/cached from Debian, this way it has to crash.

@ForsakenHarmony
Copy link
Author

it also happens in ci

@mikestead
Copy link

mikestead commented Jul 2, 2017

Having exact same issue. Fails with segmentation fault after a clean build and run inside Alpine image based on this Dockerfile (Node 8.1 + build essentials).

Works fine when doing the same thing inside image from this Dockerfile (Node 6.11 + build essentials).

@nschonni
Copy link
Contributor

nschonni commented Jul 3, 2017

Between 6 and 8, the node images changed from Alpine 3.4 to 3.6 so there may be some difference there. We did use their image to build our binaries though

@xzyfer
Copy link
Contributor

xzyfer commented Jul 3, 2017

@mikestead can you run npm rebuild node-sass --force within the Node 8.1 container and confirm whether the segfault is still present?

Also can you supply a minimal scss code sample the produces the segfault so we can investigate further?

@ForsakenHarmony
Copy link
Author

tried rebuilding in the Dockerfile, didn't change anything

@sass sass deleted a comment from franknoel Jul 4, 2017
@xzyfer
Copy link
Contributor

xzyfer commented Jul 4, 2017

@ForsakenHarmony thanks. If a fresh local recompiled binary is still segfaulting I'm not sure what we can do. This could be an issue with Node 8 or Nan.

@djskinner
Copy link

FWIW I'm seeing something similar but nothing to do with node-sass.

I've had a node application running FROM node:8-alpine for a while now with no problems. I've been toying with using babel-preset-env to transpile code in a version-aware manner. Presumably this means that more of my code is now using native ES features that are available in node 8 features rather than transpiled ES5 code.

Anyway, something has changed and the app crashes with Segmentation Fault when I try to log in (works fine up until this point). Switching the Dockerfile back to FROM node:8 fixes the issue.

@ForsakenHarmony
Copy link
Author

ForsakenHarmony commented Jul 7, 2017

https://gist.github.com/ForsakenHarmony/7efb3659dac985a90598b869b07c7e46

this is the dockerfile I tested with, project is linked in the main post

@jwalton
Copy link

jwalton commented Feb 1, 2018

This was merged in August. I wonder when and where it landed?

@cw789
Copy link

cw789 commented Feb 9, 2018

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

I had the same issue not using Sass.
It only occurs if the docker host itself has a hardened linux kernel (alpine in my case).

@saper
Copy link
Member

saper commented Feb 27, 2018

This has been worked around by increasing thread stack size in the libuv libary (libuv/libuv#1507) and became available in node 8.

Therefore using anything older than node 8 with alpine is discouraged.

@saper saper closed this as completed Feb 27, 2018
@paulmaraireland
Copy link

paulmaraireland commented Mar 18, 2018

In a nightcourse, we were asked to setup a node http server in docker.

I looked up what was good for docker and found it was alpine linux so I installed that in a VM.
Then I installed docker in that and then I followed a few basic tutorials to try and get node going.
None worked and I kept getting the error code 139.

Example 1:
Segmentation fault
The command '/bin/sh -c npm install' returned a non-zero code: 139

Example 2:
CONTAINER ID IMAGE COMMAND CREATED STATUS
107a1b769d33 webapp "node index.js" 9 seconds ago Exited (139)

I searched for a very long time and eventually I found this thread and saw the reply from @cw789 which helped. It did not explain what I should do but I pieced it together from looking at the solution and how some others patched their systems.

The fix is for me to add this to my Dockerfile before npm gets called:

RUN apt-get update -y && apt-get dist-upgrade -y && \
apt-get install -y --no-install-recommends paxctl && \
paxctl -mC `which node`

It also works if I add it just after:
FROM node:carbon

If this comment seems long and includes a lot of technical lines, it is meant to. If anyone else ends up googling the errors like I did, I hope this helps.

@xzyfer
Copy link
Contributor

xzyfer commented Mar 24, 2018

Can anyone confirm whether this is still an issue with 4.8.3?

@xakep139
Copy link

xakep139 commented Mar 27, 2018

@xzyfer I confirm, 4.8.3 cause Segmentation fault (core dumped). On 4.8.2 we have no problems

SkYNewZ added a commit to SkYNewZ/rest-fornite-api that referenced this issue Apr 3, 2018
SkYNewZ added a commit to SkYNewZ/rest-fornite-api that referenced this issue Apr 3, 2018
* Change docker image for fixing this issue sass/node-sass#2031
* `clinet.connect()` only once
* Use one variable `DATABSE_CONNECTION_STING` instead of 5 other variables
* Use 3 different account to prevent [this type](qlaffont/fortnite-api#42) of error...
@sass sass deleted a comment from ForsakenHarmony Jun 11, 2018
@happysalada
Copy link

I still have this issue on 4.10, with node:11.1-alpine

@happysalada
Copy link

happysalada commented Nov 20, 2018

I get it too on node:11.2-alpine and node:11.2-slim
if anybody else runs into this, using the full image
node:11.2 this happens less often (it still happens sometimes)

@happysalada
Copy link

using node:10.13-alpine seems to solve the problem

@testica
Copy link

testica commented May 18, 2019

I was facing the same problem serving an express server. For some reason -alpine version throw segmentation fault.

Using just node:8 solved my problem

@kozr
Copy link

kozr commented Sep 27, 2019

Using node:10.16.3 gave me seg fault, and changing it to node:8 or node:latest as of 2019 Sept 27th worked for me.

@superern
Copy link

using node:10.13-alpine seems to solve the problem

This resolves our problem.

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

No branches or pull requests