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

TypeError: Cannot read properties of undefined (reading 'replace') #923

Open
alexgleason opened this issue Aug 2, 2024 · 7 comments · May be fixed by #944
Open

TypeError: Cannot read properties of undefined (reading 'replace') #923

alexgleason opened this issue Aug 2, 2024 · 7 comments · May be fixed by #944

Comments

@alexgleason
Copy link

I'm getting some kind of error, but the error handler itself has an error, so I'm not sure what the error is. 😃

error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'replace')
      stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
                                               ^
    at queryError (https://deno.land/x/[email protected]/src/connection.js:392:48)
    at errored (https://deno.land/x/[email protected]/src/connection.js:387:17)
    at error (https://deno.land/x/[email protected]/src/connection.js:379:5)
    at https://deno.land/x/[email protected]/polyfills.js:138:30
    at Array.forEach (<anonymous>)
    at call (https://deno.land/x/[email protected]/polyfills.js:138:16)
    at error (https://deno.land/x/[email protected]/polyfills.js:131:5)
    at eventLoopTick (ext:core/01_core.js:168:7)
@alexgleason
Copy link
Author

alexgleason commented Aug 2, 2024

So I edited the code manually and logged it. err is:

InvalidData: invalid peer certificate: UnknownIssuer
    at async TlsConn.read (ext:deno_net/01_net.js:150:15)
    at async success (https://raw.githubusercontent.com/alexgleason/postgres.js/51ac395234089d5b7806c471830a1a472958fb06/deno/polyfills.js:97:56) {
  name: "InvalidData"
}

And the value of query is... true ???

EDIT: It's because query is being set to true here:

initial = query || true

@marbemac
Copy link

Running into this as well

@patrickReiis
Copy link

I'm also having this problem

@alexgleason alexgleason linked a pull request Sep 16, 2024 that will close this issue
@dhardtke
Copy link

dhardtke commented Nov 7, 2024

We are also seeing this error in our projects:

TypeError: Cannot read properties of undefined (reading 'replace')
    at queryError (/usr/src/app/node_modules/postgres/cjs/src/connection.js:389:48)
    at errored (/usr/src/app/node_modules/postgres/cjs/src/connection.js:383:14)
    at TLSSocket.data (/usr/src/app/node_modules/postgres/cjs/src/connection.js:318:9)
    at TLSSocket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:191:23)

I am not convinced it is an issue with the initial query since /usr/src/app/node_modules/postgres/cjs/src/connection.js:383:14 points to

query && queryError(query, err)

It is very problematic that we don't see the actual error. It does not happen on startup but when our NodeJS backend is under high load.

@arenddeboer
Copy link

arenddeboer commented Dec 19, 2024

I'm getting this error with target_session_attrs: 'primary' where the replica is down and the replica as first host in a multi host connection string. Will try to dig deeper.

@alexgleason
Copy link
Author

If you are using Deno you can work around this by switching to my fork with:

import postgres from "https://gitlab.com/soapbox-pub/postgres.js/-/raw/e79d7d2039446fbf7a37d4eca0d17e94a94b8b53/deno/mod.js";

I've been using this fork in a high workload application for 3 or 4 months now.

It's just the patch applied from #944

If you're on Node, perhaps edit the file in node_modules manually to apply the change from #944. That will at least give you the correct error message, which you may only need temporarily to solve the issue.

@arenddeboer
Copy link

Thanks @alexgleason
I'm on node.js and the timeout seems to trigger connectTimedOut() which calls errored() which calls queryError().
As this only happens during startup and the reconnecting mechanism to other hosts in the host string works at runtime, I will resort to sorting the host string with the primary first before initializing.

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

Successfully merging a pull request may close this issue.

6 participants
@marbemac @dhardtke @alexgleason @arenddeboer @patrickReiis and others