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

track().promise and flush().promise never resolves #737

Open
oluckyman opened this issue May 6, 2024 · 1 comment
Open

track().promise and flush().promise never resolves #737

oluckyman opened this issue May 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@oluckyman
Copy link

oluckyman commented May 6, 2024

Expected Behavior

I expect await track|flush().promise to resolve

Current Behavior

It awaits forever.

Possible Solution

I nailed down the issue is in transports/http:

          if (res.complete && responsePayload.length > 0) {
            try {
              // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
              var parsedResponsePayload = JSON.parse(responsePayload);
              var result = _this.buildResponse(parsedResponsePayload);
              console.log("RESOLVING RESULT!", result);
              resolve(result);
              return;
            } catch (_a) {
              resolve(null);
            }
          }
        });

This code never runs because res.complete is false, even though the server returns the correct result and registers the event:

{"code":200,"server_upload_time":1714999800311,"payload_size_bytes":274,"events_ingested":1}

Steps to Reproduce

import { flush, init, track, Types } from '@amplitude/analytics-node'
const client = init('my-key')
const logEvent: async () => {
    track('command', { command: 'bla bla' }, {
      user_id: userId,
    }).promise.then((res) => {
      // this func never runs
      return res
    })
    const f = flush()
    console.log(f.promise) // shows Promise { <pending> }
    console.log('now lets wait')
    const res = await f.promise
    console.log('got it', res) // never arrives to this line
}

Environment

  • JS SDK Version: analytics-node@1.3.5
  • Installation Method:
    via npm into Deno:
// deno.json
{
  "imports": {
    "@amplitude/analytics-node": "npm:@amplitude/analytics-node@1.3.5"
  }
}
  • Browser and Version: server environment
@oluckyman oluckyman added the bug Something isn't working label May 6, 2024
@oluckyman oluckyman changed the title track().promise and flush().promise never returns track().promise and flush().promise never resolves May 6, 2024
@sosafe-ugonna-ofoegbu
Copy link

sosafe-ugonna-ofoegbu commented May 30, 2024

Currently having similar issue with identify().promise using package analytics-browser.
It never resolves.
Probably something related to changes made here

export const convertProxyObjectToRealObject = <T>(instance: T, queue: QueueProxy): T => {

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

2 participants