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(analytics-browser): should send batches sequentially #935

Merged
merged 1 commit into from
Dec 17, 2024

Conversation

Mercy811
Copy link
Contributor

@Mercy811 Mercy811 commented Dec 17, 2024

Summary

AMP-118975

Fix the issue that events are not received by order by the server. The root cause is that Promise.all() executes calls concurrently thus resolve order is not guaranteed. Fix it by sending batches sequentially, in other words, only send the next batch when the preceding one resolves.

See comment for additional notes.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

@Mercy811 Mercy811 requested a review from izaaz December 17, 2024 00:22
@Mercy811 Mercy811 merged commit ad319d6 into main Dec 17, 2024
7 checks passed
@Mercy811 Mercy811 deleted the AMP-118975-fix-should-send-batches-in-order branch December 17, 2024 01:05
Comment on lines +156 to +159
await batches.reduce(async (promise, batch) => {
await promise;
return await this.send(batch, useRetry);
}, Promise.resolve());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just noticed that it's auto changed by Intellij

I had

await batches.reduce(
      (promise, batch) => {
        return promise.then(() => this.send(batch, useRetry))
      },
      Promise.resolve()
    );

After clicking that "convert to async function", it updated to what we have here.
image

I was expecting to have

await batches.reduce(
      async (promise, batch) => {
        await promise;
        return this.send(batch, false);
      },
      Promise.resolve()
    );

It's still working although a little bit redundant. Should clean it in AMP-120671.

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.

2 participants