brianc / node-pg-native

Native (C/C++) bindings to PostgreSQL with sync and async options.
247 stars 44 forks source link

Segfaults on node 17 #104

Open Ten0 opened 2 years ago

Ten0 commented 2 years ago

Since we've updated to node 17, using pg-native in combination with pg results in a segfault of the node process.

dzuelke commented 2 years ago

I suspect this is due to OpenSSL 3 in Node.js 17 and newer.

infinityfye commented 1 year ago

Indeed. I've confirmed those segfaults are due to OpenSSL 3.


timestamp message
1670159721000 /lib/x86_64-linux-gnu/libpthread.so.0(+0x13140)[0x7fbec4a93140]
1670159721000 /usr/lib/x86_64-linux-gnu/libssl.so.1.1(SSL_get_peer_certificate+0x13)[0x7fbec0366143]
1670159721000 /usr/lib/x86_64-linux-gnu/libpq.so.5(+0x25f1d)[0x7fbec03e6f1d]
1670159721000 /usr/lib/x86_64-linux-gnu/libpq.so.5(PQconnectPoll+0xd68)[0x7fbec03d1628]
1670159721000 /usr/lib/x86_64-linux-gnu/libpq.so.5(+0x118f7)[0x7fbec03d28f7]
1670159721000 /usr/lib/x86_64-linux-gnu/libpq.so.5(PQconnectdb+0x38)[0x7fbec03d59f8]
1670159721000 /home/node/node_modules/libpq/build/Release/addon.node(+0x8144)[0x7fbec0423144]
1670159721000 /home/node/node_modules/libpq/build/Release/addon.node(+0x9de3)[0x7fbec0424de3]
1670159721001 node[0x1647ba4]
1670159721001 /lib/x86_64-linux-gnu/libpthread.so.0(+0x7ea7)[0x7fbec4a87ea7]
1670159721001 /lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7fbec49a7a2f]
1670159722357 Segmentation fault (core dumped)

I deploy on AWS ECS and we use the official Node docker images to build and deploy on. I've encountered those on both 18-bullseye and 18-buster. So, apart from using Node16 images, are there any advice you could give?

0xkarl commented 1 year ago

Indeed. I've confirmed those segfaults are due to OpenSSL 3.

timestamp message 1670159721000 /lib/x86_64-linux-gnu/libpthread.so.0(+0x13140)[0x7fbec4a93140] 1670159721000 /usr/lib/x86_64-linux-gnu/libssl.so.1.1(SSL_get_peer_certificate+0x13)[0x7fbec0366143] 1670159721000 /usr/lib/x86_64-linux-gnu/libpq.so.5(+0x25f1d)[0x7fbec03e6f1d] 1670159721000 /usr/lib/x86_64-linux-gnu/libpq.so.5(PQconnectPoll+0xd68)[0x7fbec03d1628] 1670159721000 /usr/lib/x86_64-linux-gnu/libpq.so.5(+0x118f7)[0x7fbec03d28f7] 1670159721000 /usr/lib/x86_64-linux-gnu/libpq.so.5(PQconnectdb+0x38)[0x7fbec03d59f8] 1670159721000 /home/node/node_modules/libpq/build/Release/addon.node(+0x8144)[0x7fbec0423144] 1670159721000 /home/node/node_modules/libpq/build/Release/addon.node(+0x9de3)[0x7fbec0424de3] 1670159721001 node[0x1647ba4] 1670159721001 /lib/x86_64-linux-gnu/libpthread.so.0(+0x7ea7)[0x7fbec4a87ea7] 1670159721001 /lib/x86_64-linux-gnu/libc.so.6(clone+0x3f)[0x7fbec49a7a2f] 1670159722357 Segmentation fault (core dumped) I deploy on AWS ECS and we use the official Node docker images to build and deploy on. I've encountered those on both 18-bullseye and 18-buster. So, apart from using Node16 images, are there any advice you could give?

same. trying to use this on aws lambda w/ a custom image and getting that error:

FROM public.ecr.aws/lambda/nodejs:16

RUN yum update -y && yum install -y postgresql-devel python3 @development
COPY package.json ${LAMBDA_TASK_ROOT}
RUN npm install
...
0xkarl commented 1 year ago

got it working with libpq:

FROM public.ecr.aws/lambda/nodejs:16

RUN yum update -y && \
  yum remove postgresql postgresql-devel -y && \
  yum install -y python3 make gcc perl-core pcre-devel wget zlib-devel @development readline-devel && \
  curl -o openssl.tar.gz https://www.openssl.org/source/openssl-1.1.1s.tar.gz && \
  tar -xvf openssl.tar.gz && \
  cd openssl-1.1.1s/ && \
  ./config --prefix=/usr --openssldir=/etc/ssl --libdir=lib no-shared zlib-dynamic && \
  make && \
  make test && \
  make install && \
  cd .. && \
  curl -o postgresql.tar.gz http://ftp.postgresql.org/pub/source/v13.7/postgresql-13.7.tar.gz && \
  tar -xvf postgresql.tar.gz && \
  cd postgresql-13.7/ && \
  ./configure --prefix=/usr && \
  make && \
  make install
COPY package.json ${LAMBDA_TASK_ROOT}
RUN npm install
...
wzrdtales commented 1 year ago

@brianc is this going to be fixed?

maclockard commented 1 year ago

I think the underlying issue comes from node-libpq: https://github.com/brianc/node-libpq/issues/94.

FWIW this is still happening on node 18