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 alpine linux in Docker on arm mac #41

Closed
mahnunchik opened this issue May 26, 2022 · 9 comments
Closed

Segmentation Fault alpine linux in Docker on arm mac #41

mahnunchik opened this issue May 26, 2022 · 9 comments
Labels
more information needed Further information is requested stale This issue or pull request is old

Comments

@mahnunchik
Copy link

mahnunchik commented May 26, 2022

I've faced with the Segmentation Fault on alpine linux running in docker on arm mac.

import { ClassicLevel } from 'classic-level';

const level = new ClassicLevel('./level', {
  keyEncoding: 'buffer',
  valueEncoding: 'buffer',
});

await level.put(Buffer.from('01', 'hex'), Buffer.from('01', 'hex'));

console.log('Done!');
FROM node:16-alpine

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

ENV NODE_ENV production
COPY package* /usr/src/app/
RUN npm ci
COPY . /usr/src/app/

CMD ["npm", "start"]
% docker build -t test . 
% docker run test

> test-level-alpine@1.0.0 start
> node index.js

npm ERR! path /usr/src/app
npm ERR! command failed
npm ERR! signal SIGSEGV
npm ERR! command sh -c node index.js

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-05-26T19_40_15_807Z-debug-0.log
@mahnunchik
Copy link
Author

0 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
1 info using npm@8.5.5
2 info using node@v16.15.0
3 timing npm:load:whichnode Completed in 0ms
4 timing config:load:defaults Completed in 2ms
5 timing config:load:file:/usr/local/lib/node_modules/npm/npmrc Completed in 1ms
6 timing config:load:builtin Completed in 1ms
7 timing config:load:cli Completed in 1ms
8 timing config:load:env Completed in 0ms
9 timing config:load:file:/usr/src/app/.npmrc Completed in 0ms
10 timing config:load:project Completed in 6ms
11 timing config:load:file:/root/.npmrc Completed in 0ms
12 timing config:load:user Completed in 0ms
13 timing config:load:file:/usr/local/etc/npmrc Completed in 0ms
14 timing config:load:global Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:credentials Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 12ms
19 timing npm:load:configload Completed in 12ms
20 timing npm:load:setTitle Completed in 0ms
21 timing config:load:flatten Completed in 2ms
22 timing npm:load:display Completed in 3ms
23 verbose logfile /root/.npm/_logs/2022-05-26T19_40_15_807Z-debug-0.log
24 timing npm:load:logFile Completed in 3ms
25 timing npm:load:timers Completed in 0ms
26 timing npm:load:configScope Completed in 0ms
27 timing npm:load Completed in 18ms
28 timing command:run-script Completed in 574ms
29 timing command:start Completed in 576ms
30 verbose stack Error: command failed
30 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
30 verbose stack     at ChildProcess.emit (node:events:527:28)
30 verbose stack     at maybeClose (node:internal/child_process:1092:16)
30 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
31 verbose pkgid test-level-alpine@1.0.0
32 verbose cwd /usr/src/app
33 verbose Linux 5.10.104-linuxkit
34 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
35 verbose node v16.15.0
36 verbose npm  v8.5.5
37 error path /usr/src/app
38 error command failed
39 error signal SIGSEGV
40 error command sh -c node index.js
41 verbose exit 1
42 timing npm Completed in 690ms
43 verbose code 1
44 error A complete log of this run can be found in:
44 error     /root/.npm/_logs/2022-05-26T19_40_15_807Z-debug-0.log

@mahnunchik
Copy link
Author

Builded module from source works as expected:

FROM node:16-alpine

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

ENV NODE_ENV production
COPY package* /usr/src/app/
RUN apk add --no-cache --virtual .build-deps \
  g++ make python3 \
  && npm ci --build-from-source && npm cache clean --force \
  && apk del .build-deps

COPY . /usr/src/app/

CMD ["npm", "start"]

@vweevers vweevers added the bug Something isn't working label May 26, 2022
@juliangruber
Copy link
Member

I assume this is because of musl/glibc, have you checked whether any of https://wiki.alpinelinux.org/wiki/Running_glibc_programs fixes this?

@mahnunchik
Copy link
Author

@juliangruber rebuild from source on alpine linux npm ci --build-from-source solves the issue. So it is not related to musl.

@vweevers
Copy link
Member

vweevers commented Jun 5, 2022

I'm unable to reproduce, and verified that the prebuilt binary for alpine is loaded from node_modules/classic-level/prebuilds/linux-x64/node.napi.musl.node.

What's in your npm start script? I used CMD ["node", "index.mjs"] instead of CMD ["npm", "start"].

@vweevers vweevers added more information needed Further information is requested and removed bug Something isn't working labels Jun 5, 2022
@mahnunchik
Copy link
Author

This happens in docker on Mac M1...

@vweevers
Copy link
Member

vweevers commented Jun 7, 2022

@mahnunchik Please open a new issue with details and a way to reproduce.

@mahnunchik mahnunchik changed the title Segmentation Fault on alpine linux Segmentation Fault alpine linux in Docker on arm mac Jun 14, 2022
@mahnunchik
Copy link
Author

@vweevers I've updated original issue

@vweevers
Copy link
Member

vweevers commented Jun 14, 2022

Oh I see. I misunderstood.

I'm not familiar with this setup. I guess it's a CPU incompatibility, because the prebuilt binary was created on x64. What's the output of node -p process.arch in the docker container? And node -p process.config.variables?

@vweevers vweevers added the stale This issue or pull request is old label Nov 21, 2022
@vweevers vweevers closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more information needed Further information is requested stale This issue or pull request is old
Projects
Status: Done
Development

No branches or pull requests

3 participants