How do I stop an instance?
Function Compute has no direct interface to stop an instance. Use one of the following indirect methods based on your scenario: set a timeout, cancel client requests, stop asynchronous invocations, or delete the function.
If an instance stays active 3–5 minutes after a request finishes, check whether provisioned instances are enabled. If they are, remove them to free the instance. For more information, see Configure provisioned instances.
Choose a method
| Scenario | Recommended method |
|---|---|
| Function is running longer than expected | Set a timeout period |
| Function is synchronously invoked and you want to stop it now | Cancel client requests |
| Function has an asynchronous invocation in progress | Stop the asynchronous invocation |
| You no longer need the function | Delete the function |
Stop an instance
Set a timeout period
Set a timeout period on the function to bound execution time. When the timeout elapses, the function exits automatically and returns an error.
Consider two goals when setting the timeout:
Allow enough time for the function to complete under normal conditions.
Set a reasonable upper limit to prevent runaway executions.
For configuration steps, see Manage functions.
Cancel client requests
For synchronous invocations, cancel the request on the client side. The instance no longer processes requests after cancellation. After all in-flight requests finish and no new requests arrive for a set period, the instance is automatically reclaimed.
Stop asynchronous invocations
If the asynchronous task feature is enabled, stop a running invocation from the Function Compute console or by calling the StopStatefulAsyncInvocation API operation. After the invocation stops and no new requests arrive for a set period, the instance is automatically reclaimed.
Delete the function
Delete the function to reclaim all its instances. Any requests already allocated to those instances fail.
What's next
Instance modes — understand how Function Compute manages instance lifecycle
Manage functions — delete or modify functions