Node-postgres: NodeJS v14 support

Created on 21 Apr 2020  Â·  8Comments  Â·  Source: brianc/node-postgres

Having plenty of troubles running tests, and thus not sure how well this library works under the newly released NodeJS v14. It seems to have some problems there.

bug

Most helpful comment

v8.0.3 fixed this. Thank you guys!

All 8 comments

pg package was not trowing any error for me, it just ends execution. I was able to spot a Segmentation Fault while trying to connect with pg-native

This piece of code

const { Client } = require('pg').native
const client = new Client({
    host: 'myhost',
    user: 'threetier',
    database: 'threetier',
    password: 'threetier',
    port: 5432
});

client.on('error', err => {
  console.error('something bad has happened!', err.stack)
})

client.on('notice', msg => console.warn('notice:', msg))


const f = async () => {
    try {
        console.log('connecting...');
        await client.connect();
        console.log('querying');
        const res = await client.query('SELECT NOW() as t')
        console.log(res.rows[0].t);
        await client.end()
    } catch (e) {
        console.log('failed e', e);
    }
}

console.log('calling');
f();

Throw the following error:

[ec2-user@ip-10-0-100-72 p]$ gdb node
GNU gdb (GDB) Red Hat Enterprise Linux 8.0.1-30.amzn2.0.3
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from node...done.
(gdb) set args test.js
(gdb) run
Starting program: /home/ec2-user/.nvm/versions/node/v14.0.0/bin/node test.js
Missing separate debuginfos, use: debuginfo-install glibc-2.26-34.amzn2.x86_64
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff6d33700 (LWP 22770)]
[New Thread 0x7ffff6532700 (LWP 22771)]
[New Thread 0x7ffff5d31700 (LWP 22772)]
[New Thread 0x7ffff5530700 (LWP 22773)]
[New Thread 0x7ffff4d2f700 (LWP 22774)]
[New Thread 0x7ffff7fe7700 (LWP 22775)]
calling
connecting...
[New Thread 0x7fffdc832700 (LWP 22776)]
[New Thread 0x7fffdc031700 (LWP 22777)]
[New Thread 0x7fffdb830700 (LWP 22778)]
[New Thread 0x7fffdb02f700 (LWP 22779)]

Thread 9 "node" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffdc031700 (LWP 22777)]
0x00007fffdfdb96f7 in ssl3_cleanup_key_block () from /lib64/libssl.so.10
Missing separate debuginfos, use: debuginfo-install cyrus-sasl-lib-2.1.26-23.amzn2.x86_64 keyutils-libs-1.5.8-3.amzn2.0.2.x86_64 krb5-libs-1.15.1-37.amzn2.2.2.x86_64 libcom_err-1.42.9-12.amzn2.0.2.x86_64 libcrypt-2.26-34.amzn2.x86_64 libgcc-7.3.1-6.amzn2.0.4.x86_64 libselinux-2.5-12.amzn2.0.2.x86_64 libstdc++-7.3.1-6.amzn2.0.4.x86_64 nspr-4.21.0-1.amzn2.0.2.x86_64 nss-3.44.0-7.amzn2.x86_64 nss-util-3.44.0-4.amzn2.x86_64 openldap-2.4.44-15.amzn2.x86_64 openssl-libs-1.0.2k-19.amzn2.0.3.x86_64 pcre-8.32-17.amzn2.0.2.x86_64 postgresql-libs-10.4-5.amzn2.0.2.x86_64 sssd-client-1.16.4-21.amzn2.x86_64 zlib-1.2.7-18.amzn2.x86_64
(gdb) q
A debugging session is active.

    Inferior 1 [process 22766] will be killed.

Quit anyway? (y or n) y

Although the Segfault seems to be related to OpenSSL. At that point I realized nvm installed me Node 14.

Downgrading to Node 12 solved the issue on both pg and pg-native packages (for now)

I don't have an ETA on when native bindings will work on node 14. Depending on the size and number of breakages it might be a while & is likely something I'm going to look to the community to own more widely as I don't have time to stay on top of the C/C++ layer changes...it's hard & I haven't done professional C/C++ work now for quite a while so I'm rusty.

If there are problems w/ the pure JS version LMK in a separate issue & I'll try to get those fixed ASAP.

@brianc the issue is present on both the JS and the Native version for Node 14.

pg does not throw any error, just stops execution after calling connect()
pg-native throws segfault at the same point.

Downgrading is a working solution on both pure js and native version.

Per stack trace in my previous comment. I might be related to the version of OpenSSL used in version 12 vs 14 of node.

Node 12:

[ec2-user@ip-10-0-100-92 ~]$ node -pe process.versions
{
  node: '12.16.2',
  v8: '7.8.279.23-node.34',
  uv: '1.34.2',
  zlib: '1.2.11',
  brotli: '1.0.7',
  ares: '1.15.0',
  modules: '72',
  nghttp2: '1.40.0',
  napi: '5',
  llhttp: '2.0.4',
  http_parser: '2.9.3',
  openssl: '1.1.1e',
  cldr: '36.0',
  icu: '65.1',
  tz: '2019c',
  unicode: '12.1'
}

Node 14:

[ec2-user@ip-10-0-100-92 ~]$ node -pe process.versions
{
  node: '14.0.0',
  v8: '8.1.307.30-node.30',
  uv: '1.37.0',
  zlib: '1.2.11',
  brotli: '1.0.7',
  ares: '1.16.0',
  modules: '83',
  nghttp2: '1.40.0',
  napi: '6',
  llhttp: '2.0.4',
  openssl: '1.1.1f',
  cldr: '36.1',
  icu: '66.1',
  tz: '2019c',
  unicode: '13.0'
}

So, it might be a build thing that maybe this or another package needs to link correctly for node 14.

ah awesome this is helpful thank you! are you saying this throws an error
_whenever_ you try to connect? I don't know if its an ssl thing for the
pure JS bindings since those use the SSL bundled w/ node. Are you having
problem running the tests in pg or in pg-promise? I'll take a look at
this tomorrow AM my time! :)

On Tue, Apr 21, 2020 at 5:56 PM Gabriel Brunacci notifications@github.com
wrote:

@brianc https://github.com/brianc the issue is present on both the JS
and the Native version for Node 14.

pg does not throw any error, just stops execution after calling connect()
pg-native throws segfault at the same point.

Downgrading is a working solution on both pure js and native version.

Per stack trace in my previous comment. I might be related to the version
of OpenSSL used in version 12 vs 14 of node.

Node 12:

[ec2-user@ip-10-0-100-92 ~]$ node -pe process.versions
{
node: '12.16.2',
v8: '7.8.279.23-node.34',
uv: '1.34.2',
zlib: '1.2.11',
brotli: '1.0.7',
ares: '1.15.0',
modules: '72',
nghttp2: '1.40.0',
napi: '5',
llhttp: '2.0.4',
http_parser: '2.9.3',
openssl: '1.1.1e',
cldr: '36.0',
icu: '65.1',
tz: '2019c',
unicode: '12.1'
}

Node 14:

[ec2-user@ip-10-0-100-92 ~]$ node -pe process.versions
{
node: '14.0.0',
v8: '8.1.307.30-node.30',
uv: '1.37.0',
zlib: '1.2.11',
brotli: '1.0.7',
ares: '1.16.0',
modules: '83',
nghttp2: '1.40.0',
napi: '6',
llhttp: '2.0.4',
openssl: '1.1.1f',
cldr: '36.1',
icu: '66.1',
tz: '2019c',
unicode: '13.0'
}

So, it might be a build thing that maybe this or another package needs to
link correctly for node 14.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/brianc/node-postgres/issues/2170#issuecomment-617454747,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAMHIKTI5ZPBFNKZPTV3SDRNYQDHANCNFSM4MNTOR7Q
.

Correct, it breaks when right after calling connect(), it does not even makes it to the callback.
I tried on pg and pg-native, but not on pg-promise.

Thanks to you! :)

The initial readyState (a private/undocumented API that pg uses) of net.Socket seems to have changed from 'closed' to 'open' in Node 14.

It’s hard to fix with perfect backwards compatibility, but I think I have a patch that’s close enough.

v8.0.3 fixed this. Thank you guys!

Can confirm it's fixed for us too now, thanks for the fast response! 🎉

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lucasmrl picture lucasmrl  Â·  3Comments

KeynesYouDigIt picture KeynesYouDigIt  Â·  3Comments

AhmedBHameed picture AhmedBHameed  Â·  3Comments

dipakdas99 picture dipakdas99  Â·  3Comments

gajus picture gajus  Â·  4Comments