Flagsmith / flagsmith-nodejs-client

Flagsmith Node JS Client. Flagsmith lets you manage features flags across web, mobile and server side applications. Get builds out faster. Control who has access to new features.
https://flagsmith.com/
BSD 3-Clause "New" or "Revised" License
26 stars 22 forks source link

Request timeout not using abort signal #160

Open AlissonRS opened 1 month ago

AlissonRS commented 1 month ago

In the utils.ts file, the function below is used to send request via Fetch API:

        const requestWrapper = (): Promise<Response> => {
            return new Promise((resolve, reject) => {
                let timeoutId: NodeJS.Timeout;
                if (timeout) {
                    timeoutId = setTimeout(() => reject('error: timeout'), timeout);
                }
                return fetch(url, fetchOptions)
                    .then(res => resolve(res))
                    .catch(err => reject(err))
                    .finally(() => {
                        if (timeoutId) {
                            clearTimeout(timeoutId);
                        }
                    });
            });
        };

This is timing out the promise, but not really aborting the request, which keeps http connections open hanging.

It'd be nice if abort signal was used so the http connection is also closed.

matthewelwell commented 1 month ago

Thanks for raising this @AlissonRS, and submitting a PR. I've added a comment to the PR - let's continue the discussion there.