brianc / node-postgres

PostgreSQL client for node.js.
https://node-postgres.com
MIT License
12.26k stars 1.22k forks source link

`TypeError: this.stream.write is not a function` error when `PGSSLMODE` is set to use SSL #3294

Open alinaliBQ opened 2 months ago

alinaliBQ commented 2 months ago

When I set PGSSLMODE to require or prefer, I get TypeError: this.stream.write is not a function error when I try to run the tests under packages/pg. What could be the cause of this error? This error message is very cryptic. Have others seen this before?

Error log: (replaced full project path with simplified path)

throw-in-type-parser-tests.js
  emits error FAILED!

TypeError: this.stream.write is not a function
    at Connection.requestSsl (JavascriptDriverTest/packages/pg/lib/connection.js:122:17)
    at Connection.<anonymous> (JavascriptDriverTest/packages/pg/lib/client.js:119:13)
    at Connection.emit (node:events:517:28)
    at Object.makeClient [as client] (JavascriptDriverTest/packages/pg/test/unit/client/test-helper.js:15:21)
    at Test.action (JavascriptDriverTest/packages/pg/test/unit/client/throw-in-type-parser-tests.js:39:23)
    at Test._run (JavascriptDriverTest/packages/pg/test/suite.js:32:19)
    at Test.run (JavascriptDriverTest/packages/pg/test/suite.js:14:12)
    at Suite.run (JavascriptDriverTest/packages/pg/test/suite.js:57:10)
    at JavascriptDriverTest/node_modules/async/dist/async.js:4099:9
    at Object.process (JavascriptDriverTest/node_modules/async/dist/async.js:2347:17)

xargs: node: exited with status 255; aborting
make: *** [test-unit] Error 124
npm ERR! Lifecycle script `test` failed with error: 
npm ERR! Error: command failed 
npm ERR!   in workspace: pg@8.12.0 
npm ERR!   at location: JavascriptDriverTest/packages/pg 

Commands to reproduce this error:

cd packages/pg
PGUSER=test \
PGPASSWORD=test \
PGHOST=localhost \
PGDATABASE=postgres \
PGPORT=5432 \
PGSSLMODE=require \
npm test

System: CentOS

alinaliBQ commented 1 month ago

I found more information, the error is caused by stream being undefined at this.stream.write(serialize.requestSsl())

charmander commented 1 month ago

The tests aren’t currently written to be runnable with PG* environment variables. You might have better luck with make test-all connectionString=postgres://localhost:5432/?sslmode=require.

alinaliBQ commented 1 month ago

Ohh I see, thanks for letting me know @charmander

alinaliBQ commented 1 month ago

I realize this error seems to only be present with unit tests