CRM Development Tools Beta

TL531
Participant

Function Run Time of 2 Seconds for CRM Cards is Horrendous

Hello

 

It seems like the serverless functions that power CRM Cards time out after 2 seconds. This is troubling as most calls to outside endpoints can take more than 2 seconds to initiate ask and return.

Even more troubling and frankly embarrasing, HubSpot can't even seem to handle its own examples being uploaded. I tried to install this example:

https://github.com/HubSpot/ui-extensions-examples/tree/main/simple-form

And constantly got the following errors:

The serverless function 'crm-card' failed to execute: 2022-11-02T16:29:21.260Z 034b1579-846b-4018-bb3c-545c54751f5e Task timed out after 2.03 seconds.
Function logs
2022-11-02T16:29:21.260Z 034b1579-846b-4018-bb3c-545c54751f5e Task timed out after 2.03 seconds

So I think there's something inherently wrong with either the time limit being too conservative, or the way HubSpot is fetching and attempting to render these cards to the point where even a basic example isn't loading.

13 Replies 13
cconnors
HubSpot Employee
HubSpot Employee

Function Run Time of 2 Seconds for CRM Cards is Horrendous

HI @TL531 

 

I took a look specifically at your example, and I think the reason you're timing out is this "require()" you added:
const {PdfReader} = require('pdfreader');
When you run the base example without that (i.e. https://github.com/HubSpot/ui-extensions-examples/blob/main/simple-form/src/app/app.functions/crm-ca...), it should work fine.
 
For more context, PdfReader uses pdf2json which uses pdfparser which uses fs  
 
I believe this is an issue where we don't allow AWS Lambda to utilize the filesystem, so it just times out.
I've reached out to the appropriate team to investigate further, but you should just be able to proceed by not using pdfreader in the meantime.
CMcKay
Top Contributor

Function Run Time of 2 Seconds for CRM Cards is Horrendous

@cconnors 

I think that you might be right about the fs module being the issue, I've imported it and used it many many times, and while you can import it and read files just fine, you obviously can't write out to the read only file system. 

0 Upvotes
cconnors
HubSpot Employee
HubSpot Employee

Function Run Time of 2 Seconds for CRM Cards is Horrendous

So investigated further. The 5s timeout increase did solve the timeout problem, but there was still an syntax error under the hood where it was failing if you used node12.

 

I wasn't sure if you or anyone was getting synax errors, but I did notice that in some of our own test projects. We've since updated all https://github.com/HubSpot/ui-extensions-examples examples to use node16, so as long as you're pulling in the latest examples, you should be good now.

 

"runtime": "nodejs16.x",

 

CMcKay
Top Contributor

Function Run Time of 2 Seconds for CRM Cards is Horrendous

Sick, thanks for investigating

0 Upvotes
cconnors
HubSpot Employee
HubSpot Employee

Function Run Time of 2 Seconds for CRM Cards is Horrendous

Hi all. We just bumped up the timeout limit to 5 seconds. You'll need to rebuild/deploy again to pick up the changes as the timeout limits for our serverless are set at build time.

 

This was mostly to be in line with the default timeout of our Public App CRM Card data fetch URLs: https://developers.hubspot.com/docs/api/crm/extensions/custom-cards

Let me know if you still have issues.

CMcKay
Top Contributor

Function Run Time of 2 Seconds for CRM Cards is Horrendous

Hey @cconnors, In most development environments, there usually isn't a cap on runtime, HubSpot CMS doesn't limit website load time to 2 or 5 seconds (and it would be ludicrous if it did), old crm cards don't have this small of a timeout period. The load time has always been a thing that the developers need to watch and try to keep to a minimum, otherwise no one will want to use the app. The people using the app should be the ones deciding what the timeout period should be (because they are the ones in the end that will be negatively impacted) not hubspot. Just some thoughts, let us know what you think. I am really thankful for the 2.5 second increase though, thank you so much for that
TL531
Participant

Function Run Time of 2 Seconds for CRM Cards is Horrendous

Excellent, thank you.

0 Upvotes
cconnors
HubSpot Employee
HubSpot Employee

Function Run Time of 2 Seconds for CRM Cards is Horrendous

HI @TL531. I can understand how this would be an issue. This is a beta and we're still trying to find the right balance between the developer and customer experience, while making sure our CRM Records load in a reasonable amount of time. I'm going to bring up with my team and come up with the best next steps here.

 

In the meantime, do you have examples of which API calls your making and how many in a serverless function? That should help us determine the best limits to put in place for the future.

TL531
Participant

Function Run Time of 2 Seconds for CRM Cards is Horrendous

So I wasn't even hitting any outside APIs; I was trying to run just the examples HubSpot provides (in this case, one that interacts with a form function) and that was timing out.

 

I think ideally if we could get 10 seconds for these that would work best, because most outside endpoints terminate in 5 seconds if no response given.

0 Upvotes
sejal_parikh
HubSpot Product Team
HubSpot Product Team

Function Run Time of 2 Seconds for CRM Cards is Horrendous


@TL531 wrote:

So I wasn't even hitting any outside APIs; I was trying to run just the examples HubSpot provides (in this case, one that interacts with a form function) and that was timing out.

That ideally shouldn't happen, so I will take it to the team for more investigation. My understanding was that you were hitting an outside endpoint by modifying the code sample. So, Thanks for clarifying. 

 

@cconnors 

0 Upvotes
CMcKay
Top Contributor

Function Run Time of 2 Seconds for CRM Cards is Horrendous

Totally agree with Thomas on this one, is there any inherent reason why this isn't 10 seconds like the normal functions, besides client side load times (which has always been the job of the developer to keep efficient)? If we were able to trigger crm card functions via webhooks we could easily build workarounds for this.

cconnors
HubSpot Employee
HubSpot Employee

Function Run Time of 2 Seconds for CRM Cards is Horrendous

Hi @CMcKay. Could you elaborate more on

 


@CMcKay wrote:

If we were able to trigger crm card functions via webhooks we could easily build workarounds for this.


Are you asking about uploading serverless functions (javascript) that we expose via an API endpoint?

0 Upvotes
CMcKay
Top Contributor

Function Run Time of 2 Seconds for CRM Cards is Horrendous

No, I'm talking about the card serverless functions that are not expose by a public endpoint. 

 

0 Upvotes