Skip to content

[GCPFunction] Failure to flush leads to cloud function hanging #4809

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

Closed
3 tasks done
jtadmor opened this issue Mar 28, 2022 · 8 comments
Closed
3 tasks done

[GCPFunction] Failure to flush leads to cloud function hanging #4809

jtadmor opened this issue Mar 28, 2022 · 8 comments
Labels
Package: serverless Issues related to the Sentry Serverless SDK

Comments

@jtadmor
Copy link

jtadmor commented Mar 28, 2022

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/serverless

SDK Version

6.19.2

Framework Version

6.19.2

Link to Sentry event

No response

Steps to Reproduce

We have a project in which we happen to be over the transaction limit.

  1. Call GCPFunction.wrapHttpFunction around any function.
  2. Set tracesSampleRate: 1.0

See some errors like this show up in the logs:

"severity":"ERROR","message":"Sentry Logger [Error]: Error while sending event: SentryError: HTTP Error (429)
  at new SentryError (node_modules/@sentry/utils/dist/error.js:9:28)
  at ClientRequest.<anonymous> (node_modules/@sentry/node/dist/transports/base/index.js:213:44)
  at Object.onceWrapper (events.js:421:26)
  at ClientRequest.emit (events.js:314:20)
  at ClientRequest.EventEmitter.emit (domain.js:506:15)
  at HTTPParser.parserOnIncomingClient (_http_client.js:601:27)
  at HTTPParser.parserOnHeadersComplete (_http_common.js:122:17)
  at TLSSocket.socketOnData (_http_client.js:474:22)
  at TLSSocket.emit (events.js:314:20)
  at TLSSocket.EventEmitter.emit (domain.js:506:15)"}

Expected Result

Transactions / traces do not send, but functions continue to operate as expected.

Actual Result

Function times out.

@jtadmor
Copy link
Author

jtadmor commented Mar 28, 2022

Note: I am able to fix this issue by running the same wrapHttpFunction code locally, with this alteration to this portion

      void flush(options.flushTimeout)
        .catch((e) => {
           isDebugBuild() && logger.error(e);
           _end.call(this, chunk, encoding, cb);
        }).
        .then( // keep the rest of the code )

Basically, it seems like the issue is that it is possible not to call _end.call if flush errors in any way.

@lforst lforst pinned this issue Mar 28, 2022
@lforst lforst unpinned this issue Mar 28, 2022
@lforst
Copy link
Contributor

lforst commented Mar 28, 2022

Thanks for writing in! I investigated a bit and I believe this error occurs when sentry returns a NOK response while we are flushing the event buffer with drain().

The following section in the promise buffer will simply return a rejected promise while no consumer of drain() actually expects it to reject.

void resolvedSyncPromise(item).then(() => {
// eslint-disable-next-line no-plusplus
if (!--counter) {
clearTimeout(capturedSetTimeout);
resolve(true);
}
}, reject);

I'm not totally sure whether that's actually the issue because I didn't try to repro, but if it is we should def fix it.

@lforst lforst added Package: serverless Issues related to the Sentry Serverless SDK Status: Backlog and removed Status: Untriaged labels Mar 28, 2022
@jtadmor
Copy link
Author

jtadmor commented Mar 28, 2022

Thanks for looking into this so quickly! This mismatch in expectation makes sense. I think seeing the Sentry error in our logs is vaguely useful (or could be to others), so I'm not sure if the answer is just to swallow things locally or to explicitly .catch flush / drain calls everywhere. We have not noticed any other fallout from this issue, but will let you know if we do.

@lforst
Copy link
Contributor

lforst commented May 13, 2022

We just merged #5090 which will hopefully get rid of this problem entirely.

The SDK should not throw anymore when transmitting errors to Sentry fails. In case of an error, the SDK will simply log the error (if you set debug: true in the Sentry.init() options).

We are currently amidst preparing for the v7 release of the SDK - meaning this change will become available with the next beta or release candidate version of v7.

@fpoppinga
Copy link

We are observing the following problem, which seems to be related to this issue:

When our sentry subscription runs out of transactions (i.e. we reach for example 100k transactions included in the minimum price business subscription), our functions start to hang all the time. There is a perfect correlation in our metrics between cloud functions hanging and sentry transactions running out.

I suspect that something internally throws, when the transaction can not be reported and subsequently this issue is triggered.

As a workaround you can buy additional sentry transactions (not ideal, I'd say), and we are looking into downgrading the sentry @sentry/serverless package.

Maybe you can hotfix this in a release prior to v7?

@lforst
Copy link
Contributor

lforst commented May 30, 2022

@fpoppinga that problem should also be resolved with the fix. The v7 release will most likely happen later today. I will check back with the team about cherry picking onto v6. For now the recommendation is to upgrade.

@fpoppinga
Copy link

@lforst Thanks for getting back to me, alright, I'll look into upgrading to 7 ASAP then :)

@lforst
Copy link
Contributor

lforst commented Jun 1, 2022

Closing this because we released v7 - feel free to ping me if there are any outstanding issues!

@lforst lforst closed this as completed Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: serverless Issues related to the Sentry Serverless SDK
Projects
None yet
Development

No branches or pull requests

3 participants