-
Notifications
You must be signed in to change notification settings - Fork 36
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
Events that are captured while flush is pending remain queued until next flush #245
Comments
that is by design, so we batch things instead of sending serial requests.
true, but this usually only happens during development because of process crashing, hot reloading, etc, this is likely not happening in production unless your service is constantly crashing. @mattjennings could you for example call
This would just make the batching option useless since it's always sending what's left before the time interval or the min. amount for batching losing all the improvements for less network requests, etc. I' say this is not a bug, but a feature, but I do understand the bad UX during development, I wonder if you can come up with more ideas, I think the signal handler would be a good one, a last chance to flush everything pending before crashing. Something like https://nodejs.org/api/process.html#event-beforeexit |
My workaround was to set up a I think there are two concerns here - one is expected behaviour when In the case of
So maybe this could do for a bit more clarification on what Alternatively, if there were an option to disable batching altogether this is probably what someone would want for lambda/dev environments. As for the crashing concern, if you're able to run it in |
Bug description
This is perhaps the same issue as #232. I noticed this when using
flushAt
of 1 andflushInterval
of 0, but this can happen with any values.The issue is evident when events are captured in timeouts or async methods (as you'll see in the repro below). When an event is captured and should flush, the client will start one here. However, if another event is captured before that flush completes, that event is stuck in queue until the next flush happens, which would typically be on the next capture or shutdown if called. This is usually OK, but consider a scenario where
flushInterval
time passes and the process crashes. These events would be lost when I would have expected these to get sent, especially if flushInterval is 0. (Or, in my case, staring at the posthog dashboard wondering why my events weren't showing up during development)How to reproduce
Run this in node with posthog-node@4.0.1
Console output (note that
event_2
is captured but not flushed until the manual flush call):This also can be reproduced by capturing after awaiting a promise instead of a setTimeout.
Related sub-libraries
Additional context
I believe a simple fix is to check if the queue > flushAt when the flushPromise resolves, and if so, flush again.
The text was updated successfully, but these errors were encountered: