aerospike / aerospike-client-nodejs

Node.js client for the Aerospike database
https://www.aerospike.com/
Apache License 2.0
202 stars 78 forks source link

Can't get to work on Alpine Linux due to relocation error #286

Closed aknuds1 closed 6 years ago

aknuds1 commented 6 years ago

I'm trying to install aerospike-client-nodejs on Alpine Linux, using C library built from source, but it fails due to a mysterious relocation error. Please help me figure this one out!

The below Dockerfile reproduces the error (given a package.json file in the current directory):

FROM node:10-alpine
MAINTAINER Me

WORKDIR /app

ENV PREFIX=/opt/aerospike-client-c

RUN apk add --no-cache python2 make gcc g++ git libtool autoconf automake linux-headers \
openssl-dev zlib-dev libuv-dev

RUN git clone https://github.com/aerospike/aerospike-client-c.git && cd aerospike-client-c && \
git submodule update --init && \
make EVENT_LIB=libuv && \
mv target/* /opt/aerospike-client-c

COPY package.json .

RUN npm install aerospike
RUN node -e "require('aerospike')"

You should see an error like

/app/node_modules/bindings/bindings.js:88
        throw e
        ^

Error: Error relocating /app/node_modules/aerospike/build/Release/aerospike.node: sk_free: symbol not found
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:717:18)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at bindings (/app/node_modules/bindings/bindings.js:81:44)
    at Object.<anonymous> (/app/node_modules/aerospike/lib/aerospike.js:19:31)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
jhecking commented 6 years ago

The client used to build/run on Alpine Linux in the past. However, I can reproduce the issue using your Dockerfile. There are at least two issues that are currently causing the build to fail:

(1) In binding.gyp I need to add -lssl to link against libssl explicitly. (2) The Aerospike C client recently added a call to pthread_attr_setaffinity_np - this function does not seem to be supported on Alpine Linux.

I'll fix (1) but I'll need to talk to our C client developer re (2).

I've temporarily patched both issues in my docker image and am able to run the client.

aknuds1 commented 6 years ago

Thanks @jhecking! I'll experiment based on your suggestions.

How do you patch (2) though?

jhecking commented 6 years ago

How do you patch (2) though?

By patching the as_cpu.h header file in the Aerospike C client to remove the problematic function call.

On 31 Oct 2018, at 8:25 PM, Arve Knudsen notifications@github.com wrote:

Thanks @jhecking! I'll experiment based on your suggestions.

How do you patch (2) though?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

aknuds1 commented 6 years ago

@jhecking I made a PR for the ssl linking.

Can you explain exactly how you patched as_cpu.h? Did you just avoid calling pthread_attr_setaffinity_np (and return 0 instead)?

jhecking commented 6 years ago

Did you just avoid calling pthread_attr_setaffinity_np (and return 0 instead)?

Exactly.

On 31 Oct 2018, at 8:43 PM, Arve Knudsen notifications@github.com wrote:

@jhecking I made a PR for the ssl linking.

Can you explain exactly how you patched as_cpu.h? Did you just avoid calling pthread_attr_setaffinity_np (and return 0 instead)?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

aknuds1 commented 6 years ago

Thanks!

jhecking commented 6 years ago

@aknuds1, thanks for the PR!

The good news is that I have talked to our C client developer, and he will fix the issues with the C client on Alpine Linux, incl. the pthread_attr_setaffinity_np function dependency. (Apparently, there is a different way to set CPU affinity on Alpine Linux.)

The bad news is that we'll probably see a new C client release only next week. Once that's done, I can update the Node.js client to include the fixed C client version.

aknuds1 commented 6 years ago

Thanks @jhecking for fixing this! I made my own package of the Node.js client in the meantime, so I'm OK in the meantime :)

jhecking commented 6 years ago

This issue is fixed in v3.7.2. I was able to build an Alpine Linux docker image using this slightly modified Dockerfile:

FROM node:10-alpine
MAINTAINER Me

WORKDIR /app

RUN apk add --no-cache python2 make gcc g++ git libtool autoconf automake linux-headers \
openssl-dev zlib-dev libuv-dev

RUN git clone https://github.com/aerospike/aerospike-client-c.git && \
  cd aerospike-client-c && \
  git checkout --detach 4.3.20 && \
  git submodule update --init && \
  make EVENT_LIB=libuv

ENV PREFIX=/app/aerospike-client-c/target/Linux-x86_64

RUN npm install aerospike@3.7.2
RUN node -e "require('aerospike')"

Note the extra step git checkout --detach 4.3.20 in the C client build instructions. This is to ensure the right version of the C client is used for the given Node.js client version.

aknuds1 commented 6 years ago

Thanks @jhecking!