Got 502 from function using SvelteKit form action

Thanks in advance for your help.

My site is: dewdrops.netlify.app, no custom domain yet.

I’m running Svelte 4.2.

I couldn’t find any answers using the AI

I’m using SvelteKit Form Actions, which are run as Netlify functions under the hood. I was getting a mysterious 502 error. I cannot duplicate it locally using Netlify CLI.

I am on the free tier.

The function logs made me suspect I am hitting a memory limit when I saw messages like:

Duration: 475.46 ms Memory Usage: 100 MB Init Duration: 262.86 ms

100MB seemed like a very specific round number so I suspected a memory limit issue (though sometimes memory usage reaches 135MB).

I determined my form was submitting some unneeded data. When I cut out this unneeded data the error goes away.

Interestingly, when I add garbage hidden input fields to my form using the console in Chrome dev tools I can duplicate the issue. This suggests a data size or memory issue.

I add the fields like this:

const form = document.getElementById('yourform');
for (let i = 0; i < 130; i++) { 
	const el = document.createElement('input'); 
	el.type = 'hidden'; 
	el.value = 'RANDOM-DATA-ABC-' + i; 
	el.name = 'root_key_xxx.__id__.field_key_zzz' + i;
	
	form.appendChild(el);
}

I would like to understand what went wrong to make sure I can avoid this in the future.

I’m confused because:

  • 135MB of memory is well below the 1GB limit for Netlify functions
  • the responses come back in under 600ms, so I am not hitting the 10s time limit
  • the form submission, even with extra data, was only about 15kb. That was excessive but well under the 6MB limit for Netlify functions

At the moment, your form (I only tested login), seems to be working fine. How to reproduce the issue?