amazon-web-servicesaws-step-functions

What happens when I stop an execution in AWS Step Functions?


I was reading the API documentation an there's an action called StopExecution.

https://docs.aws.amazon.com/step-functions/latest/apireference/API_StopExecution.html

I was wondering what it does. Yes, of course, it stops the execution, but what if some task is running? Does it send a signal to stop the task like SWF does? Or just revoke the TaskToken (so the task cannot send the results back) and leave it running? Does the same happens if the task is a lambda function?

I was thinking about this because I have some long running tasks and could not find this behavior documented anywhere.

My guess: It just signals the execution as stopped and leave the task running. When the tasks calls SendTaskSuccess, it just receives an error like InvalidToken.


Solution

  • I did the testing and it turns out that SFN does absolutely nothing to stop a running task. However, if you try to SendTaskHeartbeat on a stopped execution it will throw a TaskTimedOut error.

    What I ended up doing was to verify the output of SendTaskHeartbeat, catch TaskTimedOut and proceed with the task cancellation on the worker side.

    Note: The same TaskTimedOut error happens on SendTaskSuccess/SendTaskFailure.