[Commit fix] Fix thread pool starvation under multi-concurrency#2395
Merged
Conversation
Parse AWS_LAMBDA_MAX_CONCURRENCY as integer to use as the default polling task count instead of Math.Max(2, processorCount). This ensures enough polling tasks exist to fill all available concurrency slots. Add AdjustThreadPoolSettings() to pre-size the ThreadPool to mcCount + processorCount at startup, preventing blocking handlers from starving polling task continuations of threads needed to cycle back to RAPID's /next endpoint. Without both changes, blocking handlers (Thread.Sleep, .Result, .Wait()) exhaust the ThreadPool under multi-concurrency, causing Runtime.Unavailable errors because polling tasks cannot resume their await continuations. Changes: - Utils.cs: Add GetMaxConcurrency() method, use parsed MC value in DetermineProcessingTaskCount (fallback to Math.Max(2, processorCount) for non-numeric values) - LambdaBootstrap.cs: Add AdjustThreadPoolSettings() called after AdjustMemorySettings() in RunAsync startup sequence - TestMultiConcurrencyRuntimeApiClient.cs: Make thread-safe for concurrent polling task access (ConcurrentDictionary, lock on Queue) - Add tests demonstrating fix works with MC=10/20 blocking handlers
…ol tuning Add customer-configurable environment variable AWS_LAMBDA_DOTNET_MIN_THREADS to override the ThreadPool minimum worker thread count in multi-concurrency mode. Default remains conservative at 2 * processorCount. This addresses feedback that pre-creating mcCount + processorCount threads is too aggressive. Benchmark data shows 2 * processorCount is sufficient when combined with the polling task count fix (parsing MC value), while the env var gives customers a knob to tune for heavy blocking workloads. Changes: - Constants.cs: Add ENVIRONMENT_VARIABLE_AWS_LAMBDA_DOTNET_MIN_THREADS - LambdaBootstrap.cs: AdjustThreadPoolSettings checks env var override, falls back to 2 * processorCount
philasmar
approved these changes
May 28, 2026
GarrettBeatty
approved these changes
May 28, 2026
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
Recreation of #2387 with cleaned up commits
Description of changes:
Read description here: #2387
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.