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

flush() call doesn't actually flush, but waits for the next automatic flush at configured interval instead? #715

Open
ctizen opened this issue Apr 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ctizen
Copy link

ctizen commented Apr 12, 2024

Hello,
I'm experiencing weird behavior of setGroup and flush methods of Amplitude NodeJS client in case when batching is enabled (useBatch: true).

Expected Behavior

I expect one of the following:

  • setGroup method sends request and resolves returned promise without any delays
  • Calling flush after setGroup sends all the requests and resolves all pending promises, including promise from setGroup

Current Behavior

The setGroup method waits until flush interval is over and only then it resolves the promise. The timeout is 10000ms by default (managed by flushIntervalMillis configuration option).

Manual calling of flush() doesn't help either. I've tried the following, no success:

  • const promise = ampli.setGroup(...); await Promise.all([ampli.flush(), promise]);
  • const promise = ampli.setGroup(...); ampli.flush(); await promise;

I digged into amplitude code and found this line - it's being reached when context.timeout is 0, and this is hardcoded when invoking method via execute() (see here).

What I'm trying to do here is to ensure the group is assigned in the amplitude before any other events both in service backend and frontend are sent. Thus, I need to wait until setGroup request is executed, and it might take up to 10 seconds which is not a satisfactory delay for a backend entrypoint. I've decreased flushIntervalMillis option to 1000ms for now and it helped (well, sort of), but it doesn't look like a proper solution.

Possible Solution

Please confirm if this is a bug or it's an expected behavior.

Environment

  • JS SDK Version: "@amplitude/analytics-node": "^1.0.1", actual installed version is 1.0.1. I'm pretty sure all behavior described above exists in latest version, according to what I can see in current master branch.
  • Installation Method: yarn
  • Browser and Version: Node 18.19.0
@ctizen ctizen added the bug Something isn't working label Apr 12, 2024
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

1 participant