-
Notifications
You must be signed in to change notification settings - Fork 112
Open
Description
Hello,
Recently we spotted memory leak in our Fibery-Hubspot integration and I suspect that sdk is causing it
After looking at heapsnapshots I see there is a huge amount of functions created via Bottleneck
here are urls to the files. Second snapshot was taken few days after the first one
https://qm5o798ggr.ufs.sh/f/hmIrD5vM1qJoIZx1dOE0S938yOiXZVPJxczgKor5b47WmEjt
https://qm5o798ggr.ufs.sh/f/hmIrD5vM1qJooZYpe9LP02MwkEuIciFQtDZzCBOpofxAWjR5
We create new class instance for every client so rate limit calculation is isolated per workspace
Here is the code I use for client initialisation
import {Account} from '@fibery/connector';
import {Client, DEFAULT_LIMITER_OPTIONS} from '@hubspot/api-client';
import {LRUCache} from 'lru-cache';
const clientsPerAccount = new LRUCache<string, Client>({
max: 300,
});
export const anonHubspotClient = new Client();
export const getHubspotClient = (account: Account) => {
let client = clientsPerAccount.get(account.name);
if (client) {
if (client.config.accessToken !== account.accessToken) {
client.setAccessToken(account.accessToken);
}
} else {
client = new Client({
accessToken: account.accessToken,
// For OAuth apps, each HubSpot account that installs your app is limited to 100 requests every 10 seconds (TEN_SECONDLY_ROLLING)
// https://developers.hubspot.com/docs/api/usage-details#rate-limits
limiterOptions: {
...DEFAULT_LIMITER_OPTIONS,
reservoir: 99,
reservoirRefreshAmount: 99,
reservoirRefreshInterval: 10000,
},
numberOfApiCallRetries: 4,
});
clientsPerAccount.set(account.name, client);
}
return client;
};
Thanks in advance for looking at it 🙇🏻 Please let me know if you need more details
Metadata
Metadata
Assignees
Labels
No labels