-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent access to HttpContext throught HttpContextAccessor in TryRefreshAsync #432
Changes from 7 commits
0786cb0
4f41c90
2a5f671
3e00202
0f36f38
93b6b0a
795254d
48af1e8
7ea8f56
f75183b
324fc5b
34e0086
b5dc003
6b5422c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.Configuration.AzureAppConfiguration; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.AppConfiguration.AspNetCore | ||
|
@@ -24,9 +25,15 @@ public AzureAppConfigurationRefreshMiddleware(RequestDelegate next, IConfigurati | |
|
||
public async Task InvokeAsync(HttpContext context) | ||
{ | ||
foreach (var refresher in Refreshers) | ||
// | ||
// Configuration refresh is meant to execute as an isolated background task. | ||
// To prevent access of request-based resources, such as HttpContext, we suppress the execution context within the refresh operation. | ||
using (var flowControl = ExecutionContext.SuppressFlow()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it needs a comment to explain the reasoning. A suggestion
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you get a chance to iterate on this? |
||
{ | ||
_ = refresher.TryRefreshAsync(); | ||
foreach (IConfigurationRefresher refresher in Refreshers) | ||
{ | ||
_ = Task.Run(() => refresher.TryRefreshAsync()); | ||
} | ||
} | ||
|
||
// Call the next delegate/middleware in the pipeline | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
|
||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Middleware; | ||
using Microsoft.Extensions.Configuration.AzureAppConfiguration; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.AppConfiguration.Functions.Worker | ||
|
@@ -24,9 +24,15 @@ public AzureAppConfigurationRefreshMiddleware(IConfigurationRefresherProvider re | |
|
||
public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next) | ||
{ | ||
foreach (IConfigurationRefresher refresher in Refreshers) | ||
// | ||
// Configuration refresh is meant to execute as an isolated background task. | ||
// To prevent access of request-based resources, such as HttpContext, we suppress the execution context within the refresh operation. | ||
using (var flowControl = ExecutionContext.SuppressFlow()) | ||
{ | ||
_ = refresher.TryRefreshAsync(); | ||
foreach (IConfigurationRefresher refresher in Refreshers) | ||
{ | ||
_ = Task.Run(() => refresher.TryRefreshAsync()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you mean something else? It |
||
} | ||
} | ||
|
||
await next(context).ConfigureAwait(false); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using (var flowControl = ExecutionContext.SuppressFlow())
Can you use an explicit type. It's hard to tell what type
flowControl
is from the right hand side.