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

Postgres unhandled promise rejection #1319

Closed
richardscarrott opened this issue Nov 10, 2020 · 7 comments · Fixed by #1470
Closed

Postgres unhandled promise rejection #1319

richardscarrott opened this issue Nov 10, 2020 · 7 comments · Fixed by #1470
Assignees
Labels
api: cloudtrace Issues related to the googleapis/cloud-trace-nodejs API. priority: p2 Moderately-important priority. Fix may not be included in next release. status: will not fix Invalid (untrue/unsound/erroneous), inconsistent with product, not on roadmap. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@richardscarrott
Copy link

richardscarrott commented Nov 10, 2020

We're getting unhandled promise rejections from the pg module (via postgraphile) only when the trace agent is enabled:

err: {
      "type": "Error",
      "message": "[Redacted]",
      "stack":
          [Redacted]
              at Connection.parseE (/usr/src/app/node_modules/pg/lib/connection.js:554:11)
              at Connection.parseMessage (/usr/src/app/node_modules/pg/lib/connection.js:379:19)
              at Socket.<anonymous> (/usr/src/app/node_modules/pg/lib/connection.js:119:22)
              at Socket.emit (events.js:210:5)
              at addChunk (_stream_readable.js:309:12)
              at readableAddChunk (_stream_readable.js:290:11)
              at Socket.Readable.push (_stream_readable.js:224:10)
              at TCP.onStreamRead (internal/stream_base_commons.js:182:23)
      "constraint": "[Redacted]",
      "file": "execMain.c",
      "line": "1762",
      "routine": "ExecConstraints"
    }

Environment details

System:
OS: Linux 4.9 Debian GNU/Linux 9 (stretch) 9 (stretch)
Binaries:
Node: 12.14.0 - /usr/local/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.13.4 - /usr/local/bin/npm
Packages:
@google-cloud/trace-agent@5.1.1
pg@7.6.1

Steps to reproduce

I've not got a reduced test case but in our express server using postgraphile a DB constraint violation error on insert results in an unhandled promise rejection. Removing the trace agent prevents this from occurring so I'm guessing the promise is forked by the trace agent but not handled.

@product-auto-label product-auto-label bot added the api: cloudtrace Issues related to the googleapis/cloud-trace-nodejs API. label Nov 10, 2020
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Nov 11, 2020
@bcoe bcoe added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Nov 17, 2020
@yoshi-automation yoshi-automation removed triage me I really want to be triaged. 🚨 This issue needs some love. labels Nov 17, 2020
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Feb 15, 2021
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label May 10, 2021
@michaelsafyan
Copy link
Contributor

Hi, richardscarrott!

Thank you so much for the bug report. And sorry for the delay in getting to look into it. You said you have a reduced test case that can reproduce this. Would you be willing to share it?

@richardscarrott
Copy link
Author

Hi @michaelsafyan Looks like I said I've not got a reduced test case unfortunately.

We were using postgraphile at the time but I expect it'd be easier to test it with the pg module.

@michaelsafyan michaelsafyan self-assigned this Nov 23, 2021
@vincentvanderweele
Copy link

Hi @michaelsafyan!

I just spent the last 3 days debugging this issue. It never occurred to me that tracing could be the issue, so I had to chip down our application bit by bit until the culprit was found :) As a result, I have a small reproducible example to share too:

https://github.com/vincentvanderweele/cloud-trace-unhandled-promise

We run Node with the recommended flag --unhandled-rejections=strict, which causes these unhandled promises to take down the whole process, so to us this is a pretty high-impact bug. Is fixing this on your short-term roadmap?

@vincentvanderweele
Copy link

@michaelsafyan do you have any updates on this? I personally think that the priority of this bug should be reassessed, given the reproduction scenario. Basically, this tracing library cannot be used together with Postgres unless you suppress unhandled rejection promises on application level. We had to disable Postgres tracing altogether to stop our server processes from crashing.

@michaelsafyan michaelsafyan removed their assignment Apr 7, 2022
@punya
Copy link
Contributor

punya commented Aug 16, 2022

Hi @vincentvanderweele. Sorry for the long silence on this issue, and thanks for putting together a minimal repro. We're taking a look to see if there's a better way for this library to handle the rejected promise.

@punya punya self-assigned this Aug 26, 2022
@punya
Copy link
Contributor

punya commented Aug 28, 2022

Hi @vincentvanderweele. In your repro, you patch the trace agent to make it work on pg v8. Unfortunately, pg v8 isn't actually supported. The error doesn't reproduce with Node 12 and PG v7.

As described in #1272 (comment), please consider using @opentelemetry/instrumentation-pg instead.

@punya punya closed this as completed Aug 28, 2022
@punya punya added status: will not fix Invalid (untrue/unsound/erroneous), inconsistent with product, not on roadmap. and removed 🚨 This issue needs some love. labels Aug 28, 2022
@punya
Copy link
Contributor

punya commented Aug 29, 2022

I spoke too soon - this still happens under Node v12 + PG v7. Reopening.

@punya punya reopened this Aug 29, 2022
punya added a commit to punya/cloud-trace-nodejs that referenced this issue Aug 29, 2022
punya added a commit to punya/cloud-trace-nodejs that referenced this issue Aug 29, 2022
This ensures that asynchronous work done by patching gets awaited
properly. In particular, it prevents unhandled promise rejections.

Fixes googleapis#1319.
punya added a commit to punya/cloud-trace-nodejs that referenced this issue Aug 29, 2022
This ensures that asynchronous work done by patching gets awaited
properly. In particular, it prevents unhandled promise rejections.

Fixes googleapis#1319.
punya added a commit to punya/cloud-trace-nodejs that referenced this issue Aug 29, 2022
This ensures that asynchronous work done by patching gets awaited
properly. In particular, it prevents unhandled promise rejections.

Fixes googleapis#1319.
punya added a commit to punya/cloud-trace-nodejs that referenced this issue Aug 29, 2022
This ensures that asynchronous work done by patching gets awaited
properly. In particular, it prevents unhandled promise rejections.

Fixes googleapis#1319.
punya added a commit to punya/cloud-trace-nodejs that referenced this issue Aug 29, 2022
This ensures that asynchronous work done by patching gets awaited
properly. In particular, it prevents unhandled promise rejections.

Fixes googleapis#1319.
punya added a commit to punya/cloud-trace-nodejs that referenced this issue Aug 29, 2022
This ensures that asynchronous work done by patching gets awaited
properly. In particular, it prevents unhandled promise rejections.

Fixes googleapis#1319.
punya added a commit that referenced this issue Aug 29, 2022
This ensures that asynchronous work done by patching gets awaited
properly. In particular, it prevents unhandled promise rejections.

Fixes #1319.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: cloudtrace Issues related to the googleapis/cloud-trace-nodejs API. priority: p2 Moderately-important priority. Fix may not be included in next release. status: will not fix Invalid (untrue/unsound/erroneous), inconsistent with product, not on roadmap. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants