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

Random.js fails to update DB on Node v14.5.0 #12

Open
Venryx opened this issue Feb 7, 2021 · 2 comments
Open

Random.js fails to update DB on Node v14.5.0 #12

Venryx opened this issue Feb 7, 2021 · 2 comments
Labels

Comments

@Venryx
Copy link
Contributor

Venryx commented Feb 7, 2021

Summary

The "pg" module used by "random.js" is outdated; it silently fails to connect on Node v14.5.0.

Steps to reproduce

Run the "random.js" script, with Node v14.5.0; no errors will be shown, but code will fail to perform any update operations. (the awaited promise in random() simply never resolves)

Expected results

I expect to see the "ranking" cells in the "people" table update, from the execution of the timer in random.js.

Actual results

No database updates are performed. (confirmed by checking with pgAdmin)

Additional context

OS: Windows 10
PostgreSQL: 13.1
Node: 14.5.0

Possible Solution

I ran yarn add pg@latest, and afterward the random.js script began successfully updating the people table.

I found this solution (updating the pg module) from the following comment: brianc/node-postgres#2317 (comment)

The thread shows other people with the same issue, and some discussion on the source of the issue. (apparently due to an update to the Node stream module)

@Venryx Venryx added the 🐛 bug label Feb 7, 2021
@Venryx
Copy link
Contributor Author

Venryx commented Feb 7, 2021

Actually, I found that the postgraphile client has a similar issue of being unable to connect, until postgraphile and a couple other packages are updated.

Therefore, rather than updating pg directly (and adding it to the dependency list), I found that the connection issue can be resolved (both for the frontend and backend), by updating these packages:

yarn add @graphile-contrib/[email protected]
yarn add @graphile/[email protected]
yarn add [email protected]
yarn add [email protected]

However, once these packages are updated, I found that it requires that your database password be supplied (in the connection string, or as an environment variable), otherwise you get this error (for both the client and the random.js script):

internal/crypto/keys.js:324
[pg]     throw new ERR_INVALID_ARG_TYPE(
[pg]     ^
[pg]
[pg] TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be of type string or an instance of Buffer, TypedArray, DataView, or KeyObject. Received null
[pg]     at prepareSecretKey (internal/crypto/keys.js:324:11)
[pg]     at new Hmac (internal/crypto/hash.js:111:9)
[pg]     at Object.createHmac (crypto.js:143:10)
[pg]     at createHMAC (C:\Root\Apps\@V\@Modules\graphile-engine\LiveQueryBug\Attempt2\node_modules\pg\lib\sasl.js:133:17)
[pg]     at Hi (C:\Root\Apps\@V\@Modules\graphile-engine\LiveQueryBug\Attempt2\node_modules\pg\lib\sasl.js:137:13)
[pg]     at Object.continueSession (C:\Root\Apps\@V\@Modules\graphile-engine\LiveQueryBug\Attempt2\node_modules\pg\lib\sasl.js:32:24)
[pg]     at Client._handleAuthSASLContinue (C:\Root\Apps\@V\@Modules\graphile-engine\LiveQueryBug\Attempt2\node_modules\pg\lib\client.js:257:10)
[pg]     at Connection.emit (events.js:314:20)
[pg]     at C:\Root\Apps\@V\@Modules\graphile-engine\LiveQueryBug\Attempt2\node_modules\pg\lib\connection.js:115:12
[pg]     at Parser.parse (C:\Root\Apps\@V\@Modules\graphile-engine\LiveQueryBug\Attempt2\node_modules\pg-protocol\dist\parser.js:40:17) {
[pg]   code: 'ERR_INVALID_ARG_TYPE'
[pg] }

You can see the issue described here:
brianc/node-postgres#2371
feathersjs-ecosystem/generator-feathers#607
mikro-orm/mikro-orm#866

I fixed it by supplying the database password, using an environment variable (and then opening a new shell):

PGPASSWORD=YOUR_DB_PASSWORD

In summary, two changes need to be made for the demo to work in Node 14.5+:

  1. Update the four packages, as shown at the top of this post. (to restore compatibility with latest Node's stream module)
  2. Add instructions to the readme about how the database password must be supplied, by setting the PGPASSWORD environment variable.

Would one or both of these changes be acceptable as a pull request? Or is there a different solution available/preferred?

(I'm very new to Postgraphile, and am just trying to get this live-query demo working for now, so I can evaluate its flexibility and such. With the changes above, I've managed to get the data loading on the demo page. However, the live-queries appear to not be updating; so my next task is figuring out what's wrong with the live-query system. EDIT: The live-query issue was just due to me compiling the wal2json.dll file incorrectly. With the changes above, the demo works fully now. 😃)

@benjie
Copy link
Member

benjie commented Feb 8, 2021

Hey 👋 Yes updating the dependencies would be very welcome as a single PR; you should be able to do this by deleting yarn.lock, running yarn again, and then pushing the updated yarn.lock as a PR.

As for the key issue, I think this might be related to your setup? I've not experienced that issue on Mac or Linux. I'm guessing you can fix it by using a subtly modified (e.g. more explicit) connection string? I'm not sure if that makes sense as a PR - it's been a while since I've been in the guts of this project - feel free to raise one if it's minimal effort and we'll go from there 👍

Thanks 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants