How to kill background functions?

How do I stop my background function from running? When i deploy a new build, old background functions are still running and creating logs in the Function Log View

Things I’ve tried that don’t work:

Removing the serverless function completely
Renaming the entire site
Breaking the build

My background function has a callback to itself which appears to have a bug and is stuck in an infinite loop but there doesn’t appear to be a way for me to stop it.

hey @vinh-perfectstorm ,

wow, what a perfect storm indeed! we’re thinking of ways to help you.

First, can you share some code with us - we’d like to see how you are calling the function.

We have an idea on what might help - deleting the site - but that seems pretty drastic - so we want to brainstorm some other options first.

I think i finally did something that worked. I renamed my site domain

the code is exactly as you would expect.

Inside the background function, call yourself using fetch

The background function logs appear to have finally stopped. I’m going to rename my site back to the old name, and see if the logs remain clean

        let backgroundURI = `${bodyParams.origin}/.netlify/functions/chainListener-background`;
		fetch(backgroundURI, {
			method: 'POST',
			// credentials: 'same-origin',
			body: JSON.stringify({
				chainId: bodyParams.chainId,
				origin: bodyParams.origin})
		});

Ok, i’ve been able to bring back my original site name and my background function logs appear to no longer be stuck in an infinite loop.

Obviously, we probably still want a more straightforward way to see and kill background functions, especially since they can become infinitely recursive.

On a side note, not sure if it’s related, but the problem of run-away lamda functions on aws is being solved by setting allowable concurrent calls to 0