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

Massive slowdown in using shutdownAsync vs shutdown #129

Closed
1 of 4 tasks
marcfrankel opened this issue Dec 1, 2023 · 4 comments
Closed
1 of 4 tasks

Massive slowdown in using shutdownAsync vs shutdown #129

marcfrankel opened this issue Dec 1, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@marcfrankel
Copy link

Bug description

Not sure if this has to do with some issue on the ingestion level or something but recently we noticed that calling await posthog.shutdownAsync() was holding up the execution thread for around 9 seconds! Switching from shutdownAsync to just shutdown seemed to fix the issue.

We're deploying in Next.js using vercel so under the hood these are either edge functions or AWS lambda functions. I think in this case it's an edge function.

How to reproduce

  1. Follow the advice of setting flushAt to 1, flushInterval to 0, and calling shutdownAsync() https://posthog.com/docs/libraries/node#options.
  2. Call shutdownAsync after capturing an event
  3. Experience a 9 second hang time that isn't present on the non-async shutdown version of the call

Related sub-librarie

  • All of them
  • posthog-web
  • posthog-node
  • posthog-react-native

Additional context

I think this issue might relate to edge functions on vercel. Additionally from digging into the source code, it seems like this is the only difference between the versions in posthog-node.ts:

shutdown(): void {
   void this.shutdownAsync()
}

async shutdownAsync(): Promise<void> {
    this.featureFlagsPoller?.stopPoller()
    return super.shutdownAsync()
}

So maybe it's an issue with feature flags?

Also more than possible this is a user issue and it's something I'm doing wrong. We recently moved to vercel and started noticing this slowing us down...

@marcfrankel marcfrankel added the bug Something isn't working label Dec 1, 2023
@marcfrankel
Copy link
Author

Update

Using posthog.debug() reveals the problem is:

PostHog Debug error  [PostHogFetchNetworkError: Network error while fetching PostHog] {
  error:  [AxiosError: There is no suitable adapter to dispatch the request since :
- adapter xhr is not supported by the environment
- adapter http is not available in the build] {
  message: 'There is no suitable adapter to dispatch the request since :\n- adapter xhr is not supported by the environment\n- adapter http is not available in the build',
  name: 'AxiosError',
  code: 'ERR_NOT_SUPPORT'
},
  name: 'PostHogFetchNetworkError'
}

So I believe these issues are linked: #127

@huw
Copy link

huw commented Dec 1, 2023

Definitely a duplicate of #127—but I’m commenting to add that yes, shutdown is going to be faster than await shutdownAsync because it’s not awaiting that Promise. But that means your PostHog client won’t tear down properly. Please make sure you’re calling await shutdownAsync once this gets fixed.

@benjackwhite
Copy link
Collaborator

This should be fixed in the latest version as of #132

If not please feel free to re-open.

@marandaneto
Copy link
Member

@benjackwhite assuming you forgot to close the issue, closing it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants