I'm stucked hard for a whole day with this error. When I've tried to run my docker container i've got an error Segmentation fault (core dumped)
.
So to reproduce this error I'll provide my env and code.
The first below is Dockerfile, nothing special:
FROM node:8.1.3-alpine
RUN apk add --no-cache --update krb5-dev alpine-sdk python
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app
EXPOSE 3000
CMD [ "npm", "start" ]
The problem is with invoking my npm start
script, it always fail at the npm run test-prod
which has this command "test-prod": "mocha test/**/*",
. If I remove this from npm start site is deployed without errors.
Test-prod is starting from this first test, which importing app.js with supertest:
const { describe, it, before, after } = require('mocha');
const request = require('supertest');
const app = require('../../../app.js');
const User = require('../../../models/User');
const agent = request.agent(app);
//some tests
I suppose that it can be bound with new mongoose version 4.11, which asks for auth and pass in option object but when i pass it, it warns me that it's mistake:
the options [user] is not supported
the options [pass] is not supported
Finally the app.js below main part:
require('dotenv').config();
const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const session = require('express-session');
const mongoose = require('mongoose');
const MongoStore = require('connect-mongo')(session);
const routes = require('./routes');
const app = express();
const URI = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test' ? 'mongodb://localhost/mulibwanji' : process.env.MONGODB_URI;
mongoose.connect(URI, { // In URI also I have user and pass as expected
useMongoClient: true,
user: 'login',
pass: 'pass',
});
And error from Docker logs:
2017-07-10T18:53:49.796105113Z
2017-07-10T18:53:49.802949762Z
2017-07-10T18:53:49.814928711Z Local strategy authentication
2017-07-10T18:53:49.826690115Z Login
2017-07-10T18:53:51.226982330Z Segmentation fault (core dumped)
2017-07-10T18:53:51.258175441Z npm info lifecycle [email protected]~test-prod: Failed to exec test-prod script
2017-07-10T18:53:51.258270885Z npm ERR! code ELIFECYCLE
2017-07-10T18:53:51.258406077Z npm ERR! errno 139
2017-07-10T18:53:51.258445569Z npm ERR! [email protected] test-prod: `mocha test/**/*`
2017-07-10T18:53:51.258519335Z npm ERR! Exit status 139
2017-07-10T18:53:51.258539503Z npm ERR!
2017-07-10T18:53:51.258579954Z npm ERR! Failed at the [email protected] test-prod script.
2017-07-10T18:53:51.258617042Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
And the stack trace here:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 silly lifecycle [email protected]~prestart: no script for prestart, continuing
7 info lifecycle [email protected]~start: [email protected]
8 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/usr/src/app/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
10 verbose lifecycle [email protected]~start: CWD: /usr/src/app
11 silly lifecycle [email protected]~start: Args: [ '-c',
11 silly lifecycle 'npm run build && npm run test-prod && npm run lint && npm run update-schema && node ./bin/www' ]
12 silly lifecycle [email protected]~start: Returned: code: 139 signal: null
13 info lifecycle [email protected]~start: Failed to exec start script
14 verbose stack Error: [email protected] start: `npm run build && npm run test-prod && npm run lint && npm run update-schema && node ./bin/www`
14 verbose stack Exit status 139
14 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:283:16)
14 verbose stack at emitTwo (events.js:125:13)
14 verbose stack at EventEmitter.emit (events.js:213:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack at emitTwo (events.js:125:13)
14 verbose stack at ChildProcess.emit (events.js:213:7)
14 verbose stack at maybeClose (internal/child_process.js:897:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)
15 verbose pkgid [email protected]
16 verbose cwd /usr/src/app
17 verbose Linux 4.11.9-coreos
18 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
19 verbose node v8.1.3
20 verbose npm v5.0.3
21 error code ELIFECYCLE
22 error errno 139
23 error [email protected] start: `npm run build && npm run test-prod && npm run lint && npm run update-schema && node ./bin/www`
23 error Exit status 139
24 error Failed at the [email protected] start script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 139, true ]
I will appreciate so much any suggestions, thanks.
Seems like bcrypt has uploaded pre-compiled versions of bcrypt that is incompatible with the musl alpine libc. I added the following to my Dockerfile:
RUN npm rebuild bcrypt --build-from-source
And it automagically started working. I couldn't revert to 7 either, because then I got some other issue with the binary not being compatible.
bcrypt could be a secondary dependency in your case, explaining your behavior.
For me it stopped working on the 7th of July. Although the latest release of bcrypt was published in february, I still think it's possible to "update" a release and maybe they added the pre compiled versions at that date, I don't know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With