Possible thread pool starvation detected & DrainMode mode enabled

john john Pter 1,015 Reputation points
2025-05-01T23:10:29.08+00:00

I have an Azure Function that runs using .net core 8 and which uses Premium plan, now i found the following messages inside the logs:-

2025-05-01T22:51:12Z [Warning] [HostMonitor] Host CPU threshold exceeded (96 >= 80)

2025-05-01T22:51:24Z [Warning] [HostMonitor] Host CPU threshold exceeded (93 >= 80)

2025-05-01T22:51:24Z [Warning] Possible thread pool starvation detected.

2025-05-01T22:54:35Z [Information] DrainMode mode enabled

2025-05-01T22:54:35Z [Information] Calling StopAsync on the registered listeners

2025-05-01T22:54:35Z [Information] Stopping the listener 'Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener' for function 'FunctionCall-Iteration1'

2025-05-01T22:54:35Z [Information] Stopped the listener 'Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener' for function 'FunctionCall-Iteration1'

2025-05-01T22:54:35Z [Information] Stopping the listener 'Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener' for function 'FunctionCall-Iteration2'

2025-05-01T22:54:35Z [Information] Stopped the listener 'Microsoft.Azure.WebJobs.Host.Listeners.SingletonListener' for function 'FunctionCall-Iteration2'

2025-05-01T22:54:35Z [Information] Call to StopAsync complete, registered listeners are now stopped

2025-05-01T22:55:57Z [Information] LeadsData successfully processed.

2025-05-01T22:56:02Z [Information] Executed 'Functions.FunctionCall-Iteration2' (Succeeded, Id=77160cb7-7a1f-45fd-ac14-1180e4a164a1, Duration=301998ms)

so i can see messages such as:-

  1. "Possible thread pool starvation detected"
  2. "DrainMode mode enabled"
  3. "Host CPU threshold exceeded"
  4. "Stopped the listener"

and at the same time i got "LeadsData successfully processed.",, which means my code did not return any exception,, so what is going on? and how i can prevent those warnings? and can these warnings cause the code to raise exceptions?

Thanks

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,745 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Khadeer Ali 5,055 Reputation points Microsoft External Staff Moderator
    2025-05-07T12:37:06.4466667+00:00

    @john john Pter ,

    Thank you for reaching out.

    We’ve reviewed the log messages you observed, including:

    Host CPU threshold exceeded

    Possible thread pool starvation detected

    DrainMode mode enabled

    These warnings are generated by the Azure Functions host monitoring system when it detects that the environment may be under resource pressure. It's important to note that these are informational warnings and do not indicate a failure in your function logic — especially since your function has completed successfully.

    To proactively maintain performance and avoid potential delays or scaling limitations, we recommend trying the following optimizations:

    • Throttling Concurrent Workloads
      If you're using triggers such as Service Bus, Event Hub, or Queues, consider adjusting concurrency settings like maxConcurrentCalls to better manage throughput according to your app's resource profile.
      Service Bus Trigger – Concurrency
    • Scale Configuration
      Since you're using a Premium Plan, you may benefit from increasing the minimum instance count or upgrading to a higher SKU (e.g., EP2 or EP3) if your workload is CPU-intensive.
      Azure Functions Premium Plan - Scaling
    • Optimize Function Code
      Ensure all I/O-bound operations are properly awaited, and any CPU-heavy tasks are handled efficiently — ideally in smaller batches or offloaded to separate processes if needed.
      Optimize Function Performance
    • Monitoring & Insights
      We recommend enabling Azure Application Insights to track key metrics, such as thread pool usage, CPU load, and function execution times. This can help identify bottlenecks early and guide further optimizations.
      Monitor Azure Functions with Application Insights

    The same is discussed in the following GitHub post: Azure Functions - Thread Pool Starvation.

    These steps are safe to implement and not interrupt your current operations. They are designed to improve your app’s stability and responsiveness, especially during peak load conditions.

    Hope this helps. Do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for "Was this answer helpful." And if you have any further questions, let us know.


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.