Skip to content

Commit

Permalink
Merged PR 40657: Fix exit AcceptLoop in Http.Sys (#57319)
Browse files Browse the repository at this point in the history
If an exception occurs during request processing we weren't exiting the accept loop which resulted in duplicating the accept loop.

Co-authored-by: Brennan Conroy <brecon@microsoft.com>
  • Loading branch information
wtgodbe and BrennanConroy authored Aug 13, 2024
1 parent 506512f commit 15d22a9
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/Servers/HttpSys/src/MessagePump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,29 +279,38 @@ private async Task ExecuteAsync()
continue;
}

try
if (_preferInlineScheduling)
{
if (_preferInlineScheduling)
try
{
await requestContext.ExecuteAsync();
}
else
catch (Exception ex)
{
// Request processing failed
// Log the error message, release throttle and move on
Log.RequestListenerProcessError(_messagePump._logger, ex);
}
}
else
{
try
{
// Queue another accept before we execute the request
ThreadPool.UnsafeQueueUserWorkItem(this, preferLocal: false);

// Use this thread to start the execution of the request (avoid the double threadpool dispatch)
await requestContext.ExecuteAsync();

// We're done with this thread
return;
}
}
catch (Exception ex)
{
// Request processing failed
// Log the error message, release throttle and move on
Log.RequestListenerProcessError(_messagePump._logger, ex);
catch (Exception ex)
{
// Request processing failed
// Log the error message, release throttle and move on
Log.RequestListenerProcessError(_messagePump._logger, ex);
}

// We're done with this thread, accept loop was continued via ThreadPool.UnsafeQueueUserWorkItem
return;
}
}

Expand Down

0 comments on commit 15d22a9

Please sign in to comment.