How can I kill an Azure Container Apps dynamic session?

Emilio Garza 20 Reputation points
2024-12-10T05:33:11.1866667+00:00

I'm using Azure Container Apps dynamic sessions (custom container) to run user-submitted code on my application and I like it so far. However, I need these sessions to run once, then be terminated/deallocated to make space for more sessions and also to prevent paying for the additional session running time.

The problem is that there aren't any endpoints that I can use to kill a specific session. Could I maybe stop the docker container from the inside somehow? How could I stop a session as soon as the user-submitted code is finished running? I'm aware of the cooldown period config that takes down inactive sessions, though the minimum value is 300 seconds - that's unreasonable considering every execution takes 1-3 seconds max on my end.

Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
686 questions
0 comments No comments
{count} votes

Accepted answer
  1. Deepanshukatara-6769 16,565 Reputation points Moderator
    2024-12-10T06:17:24.7466667+00:00

    Hello , Welcome to MS Q&A

    I think there are no direct method to kill a specific session in Azure Container Apps. However, you can manage the lifecycle of your container by implementing logic within the container itself. Here are a few approaches you might consider:

    1. Graceful Shutdown from Inside the Container:
      • You can modify your application code to exit the container process once the user-submitted code has finished running. This will cause the container to stop, effectively ending the session.
      • For example, in a Python application, you could use sys.exit() to terminate the process.
    2. Using Azure Container Apps Job:
      • If your workload is short-lived and runs for a few seconds, consider using Azure Container Apps Jobs. Jobs are designed for running tasks that start, run to completion, and then stop. This might be more suitable for your use case than a long-running container app.

    References:

    Please let me know if any more questions

    Kindly accept if it helps

    Thanks

    Deepanshu

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.