fingerprintjs-pro-server-api-node-sdk icon indicating copy to clipboard operation
fingerprintjs-pro-server-api-node-sdk copied to clipboard

Using node-fetch with v5 causing request to hang

Open ohana54 opened this issue 1 year ago • 4 comments

Hi,

I'm trying to upgrade the sdk from v3 to v5. When using the getVisitorHistory API, the request hangs. I debugged the flow and it is caused by the cloning of the response. If I edit the code and remove the clone call, it works fine.

More info on why - https://github.com/node-fetch/node-fetch/issues/1131

Note I'm using node-fetch v2, and not the native fetch function, but according to the above bug report, seems like it can happen with native fetch as well.

Is there a reason for the response cloning? From reading the issue above and in other places, both responses should be consumed, but I'm not an expert on that area.

Would love your take on this, thank you!

ohana54 avatar Oct 03 '24 14:10 ohana54

Hi @ohana54,

Could you provide a minimal code reproduction of the issue? I tried it like this but I wasn't able to reproduce it either with native fetch nor node-fetch v2.7.0. on Node 18.

import {
  FingerprintJsServerApiClient,
  Region,
} from "@fingerprintjs/fingerprintjs-pro-server-api";
import nodeFetch from "node-fetch";

const client = new FingerprintJsServerApiClient({
  apiKey: "redacted",
  region: Region.EU,
  // @ts-ignore
  fetch: nodeFetch,
});

// Get visit history of a specific visitor
client.getVisitorHistory("redacted").then((visitorHistory) => {
  console.log(visitorHistory);
});

This code works as expected for me.

JuroUhlar avatar Oct 07 '24 15:10 JuroUhlar

Hi, I believe it only happens when the response is big enough. I have a specific visitorId that I used to reproduce the issue with the same code you wrote (returns 100 history items).

Did you reproduce a case where the response was also big? If you need the specific visitor id I used, and it's considered sensitive information, maybe I can send it via other means or talk through our contact point at Fingerprint.

Appreciate the help!

ohana54 avatar Oct 07 '24 15:10 ohana54

You are right, I was able to reproduce the issue using a visitor ID with a lot of visits and nodeFetch. Seems to work fine with the native fetch.

The rationale behind cloning the response was to provide users with the expected data (we must consume the response to do it), but also give them the ability to examine the entire network response if needed. We can discuss different ways of achieving that.

Just to get the full context, how important is it for you to use node-fetch, why not the native fetch function? Thanks a lot for reporting the issue.

JuroUhlar avatar Oct 09 '24 19:10 JuroUhlar

I'm working on a codebase that uses network mocking which is not yet compatible with native fetch. I tried upgrading to an experimental version that supports it, but it caused a lot of issues. It might still be possible to do it, although I wanted to raise this issue regardless.

To give even more context, the reason for the upgrade is because errors thrown in v3 are stringified in a way that don't provide any information. We sometimes get an error from the sdk, and to investigate further we need to upgrade to v5 to at least see the error message.

In case this issue is not a priority from your side, or maybe even prefer to drop node-fetch, I completely understand, I have a few alternative paths forward to deal with this.

Thanks!

ohana54 avatar Oct 09 '24 20:10 ohana54