PostHog / posthog-js-lite

Reimplementation of posthog-js to be as light and modular as possible.
https://posthog.com/docs/libraries
MIT License
63 stars 31 forks source link

Fetching feature flags retries for too long - not configurable #195

Closed paularmstrong closed 7 months ago

paularmstrong commented 7 months ago

Bug description

There is currently an outage on the posthog service side for feature flags. This is causing my server to thrash – continually logging network errors when trying to call posthog.getAllFlags()

This is caused by fetchWithRetry, which by default calls 4 times, with a 5 second delay between each call, resulting in requests on the server stalling for 20+ seconds: https://github.com/PostHog/posthog-js-lite/blob/c59c9d6b13bc972e0b1b3b66fe7a6c6a0e22f0ab/posthog-core/src/index.ts#L295

This retry is not configurable from the getAllFlags() endpoint (or any others that I'm seeing)

How to reproduce

  1. Take posthog down
  2. Call posthog.getAllFlags()
  3. Wait forever

Related sub-libraries

Additional context

Thank you for your bug report – we love squashing them!

marandaneto commented 7 months ago

@paularmstrong sorry about that.

The retry is configurable, see the options: https://github.com/PostHog/posthog-js-lite/blob/c59c9d6b13bc972e0b1b3b66fe7a6c6a0e22f0ab/posthog-core/src/types.ts#L23-L28 I made a PR to improve the default values and fix a typo https://github.com/PostHog/posthog-js-lite/pull/196 or https://github.com/PostHog/posthog-js-lite/blob/c59c9d6b13bc972e0b1b3b66fe7a6c6a0e22f0ab/posthog-node/src/posthog-node.ts#L20-L23 but the logic for node is different, @neilkakkar maybe can you confirm if that's the case?

neilkakkar commented 7 months ago

It should be the same, uses the same base class 👍

neilkakkar commented 7 months ago

To follow up, I'll add more sensible defaults for flags, since indeed this needs to be fast and ok not to retry, vs, say, sending events to posthog