Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@ class Analytics {

if (!this.flushed) {
this.flushed = true
this.flush()
this.flush(callback)
return
}

if (this.queue.length >= this.flushAt) {
this.flush()
this.flush(callback)
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird bug, may not cause issues, but this actually causes the callback to be called twice now as its the exact same callback pulled from the item when flushed.
https://github.com/segmentio/analytics-node/blob/master/index.js#L247-L259

Copy link
Contributor

Choose a reason for hiding this comment

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

cc - @pbassut

Choose a reason for hiding this comment

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

Yes, the callback is running twice for me as well. Is there a plan to fix that? Or should I log a new issue?

Copy link
Contributor

Choose a reason for hiding this comment

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

We should have a fix ASAP

Choose a reason for hiding this comment

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

Hi. Was the fix for this released with v5.1.0?

Copy link
Contributor

Choose a reason for hiding this comment

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

@pooyaj It's fixed locally. I'm writing some tests and I'll create a PR for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@BrandonNoad Can you give me a minimal working example that illustrates the issue?

For issue #1: seems unlikely given they're only called when the request to segment servers actually finishes(successfully or not).

As for issue #2: I'll have to see some code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@BrandonNoad Please open a new issue for it though.

Choose a reason for hiding this comment

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

@pbassut Yes, I can open a new issue with some code to reproduce the behaviour.

For issue #1: seems unlikely given they're only called when the request to segment servers actually finishes(successfully or not).

I may have been incorrect in saying "too early". That was just an assumption based on the fact that the callback is being called twice and in the first call, batch is undefined.

Choose a reason for hiding this comment

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

New issue is here: #300

}

if (this.flushInterval && !this.timer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's also another one here:

this.timer = setTimeout(this.flush.bind(this), this.flushInterval)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, @pbassut
just applied the suggestion!

this.timer = setTimeout(this.flush.bind(this), this.flushInterval)
this.timer = setTimeout(this.flush.bind(this, callback), this.flushInterval)
}
}

Expand Down