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

fix(serverless): wrapEventFunction does not await for async code #3740

Merged
merged 5 commits into from
Jun 25, 2021

Conversation

ahmedetefy
Copy link
Contributor

@ahmedetefy ahmedetefy commented Jun 23, 2021

This PR:-

  • Awaits async code in GCP functions wrapEventFunction because google cloud expects us to either await async code or return a promise

When working with asynchronous tasks that involve callbacks or Promise objects, you must explicitly inform the runtime that your function has finished executing these tasks

Ref: https://cloud.google.com/functions/docs/concepts/nodejs-runtime#signal-termination

fixes: #3325

@ahmedetefy ahmedetefy force-pushed the ahmed-fix-serverless-gcp-async branch from 5583570 to ab3e6e4 Compare June 23, 2021 13:36
@ahmedetefy ahmedetefy changed the title fix(serverless): wrapEventFunction does not await for async fix(serverless): wrapEventFunction does not await for async code Jun 23, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jun 23, 2021

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 21.01 KB (-1.57% 🔽)
@sentry/browser - Webpack 21.95 KB (-1.86% 🔽)
@sentry/react - Webpack 21.99 KB (-1.86% 🔽)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.47 KB (-1.27% 🔽)

@HazAT HazAT self-assigned this Jun 24, 2021
@HazAT HazAT marked this pull request as ready for review June 24, 2021 13:11
@HazAT HazAT requested a review from kamilogorek as a code owner June 24, 2021 13:11
@ahmedetefy
Copy link
Contributor Author

@HazAT This PR wouldn't solve this -> #3695

.then(() => (fn as CloudEventFunction)(context))
.then(
result => {
newCallback(null, result);
return newCallback(null, result);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we write result => newCallback(null, result) prettier should format it nicely

@@ -72,14 +72,14 @@ function _wrapCloudEventFunction(
return (fn as CloudEventFunctionWithCallback)(context, newCallback);
}

void Promise.resolve()
return Promise.resolve()
Copy link

@danieljimeneznz danieljimeneznz Jun 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this fix been tested on GCP using the example that @killthekitten provided in the example?

My only concern with this is that the top level function i.e. L37 is returning a non-asynchronous function to the GCP runner, so the promises within the function might not be correctly resolved within the runners lifecycle? (I might be wrong)

If my above concern is valid, it would be helpful to have the following expectations in the tests:

expect(wrappedHandler).toBeInstanceOf(Promise);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we tested it and it works.

@HazAT HazAT merged commit 460994d into master Jun 25, 2021
@HazAT HazAT deleted the ahmed-fix-serverless-gcp-async branch June 25, 2021 07:16
1999 added a commit to 1999/sentry-javascript that referenced this pull request Jun 25, 2021
…transport

* upstream/master: (29 commits)
  ref: Always use lowercase files (getsentry#3742)
  feat: Make dedupe integration default for browser (getsentry#3730)
  ref(ember): Allow initing Ember without config entry (getsentry#3745)
  fix(serverless): wrapEventFunction does not await for async code (getsentry#3740)
  Metrics: Tag CLS elements (getsentry#3734)
  feat: Add Next.js 11 to supported peer dependencies list (getsentry#3711)
  test: Run integration tests for Next 10/11 and Webpack 4/5 matrix (getsentry#3741)
  fix: Correctly limit Buffer requests (getsentry#3736)
  Whoops. Remove pinned node version from package.json
  ref: Introduce test runner for node session health tests (getsentry#3728)
  fix: Prevent circular structure serialization in events (getsentry#3727)
  ref(node): Update Node manual tests and test for sessionCount (getsentry#3726)
  ref(ember): Update scenarios and remove a few to speed up tests (getsentry#3720)
  docs: Fix typos (getsentry#3716)
  fix(ember): Fix ember test flake (getsentry#3719)
  release: 6.7.2
  ci: fix ember flaky test (getsentry#3718)
  misc: changelog for release 6.7.2 (getsentry#3717)
  fix(release-health): Prevent sending terminal status session updates (getsentry#3701)
  ref: Make beforeSend more strict (getsentry#3713)
  ...
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 this pull request may close these issues.

Wraping a function Sentry.GCPFunction.wrapEventFunction leads to premature function exit
4 participants