Adds support for configuration hot reload. Closes #247#1486
Merged
waldekmastykarz merged 6 commits intodotnet:mainfrom Jan 8, 2026
Merged
Adds support for configuration hot reload. Closes #247#1486waldekmastykarz merged 6 commits intodotnet:mainfrom
waldekmastykarz merged 6 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request adds configuration hot reload support to Dev Proxy, allowing the application to automatically restart when the configuration file changes. The implementation introduces a ConfigFileWatcher service that monitors the config file using FileSystemWatcher, coordinates graceful proxy shutdown, and triggers application restart through a loop in the main program. Additionally, the PR implements proper disposal patterns across all plugins by making BasePlugin implement IDisposable and updating derived plugins to dispose their resources correctly.
Key changes:
- Adds
ConfigFileWatcherhosted service to monitor configuration file changes with debouncing - Implements restart loop in
Program.csthat waits for complete proxy shutdown before restarting - Updates
BasePluginto implementIDisposableand adds disposal overrides to 15+ plugin classes
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| DevProxy/Proxy/ConfigFileWatcher.cs | New hosted service that watches config file and coordinates restart via static properties |
| DevProxy/Program.cs | Restructured to support restart loop with proper cleanup between restarts |
| DevProxy/Proxy/ProxyEngine.cs | Enhanced cleanup to remove endpoints and signal when proxy fully stopped |
| DevProxy/Extensions/IServiceCollectionExtensions.cs | Registered ConfigFileWatcher as hosted service |
| DevProxy.Abstractions/Plugins/BasePlugin.cs | Implemented IDisposable with virtual Dispose pattern and updated Configuration property to use field keyword |
| DevProxy.Abstractions/Plugins/BaseLoader.cs | Improved thread safety by marking _isDisposed as volatile and checking it before processing changes |
| DevProxy.Plugins/Reporting/MinimalCsomPermissionsPlugin.cs | Added Dispose override to clean up _loader |
| DevProxy.Plugins/Reporting/GraphMinimalPermissionsPlugin.cs | Added pragma to suppress false positive CA2213 warning for DI-injected HttpClient |
| DevProxy.Plugins/Reporting/GraphMinimalPermissionsGuidancePlugin.cs | Added pragma to suppress false positive CA2213 warning for DI-injected HttpClient |
| DevProxy.Plugins/Reporting/ApiCenterProductionVersionPlugin.cs | Added Dispose override to clean up _apiCenterClient |
| DevProxy.Plugins/Reporting/ApiCenterMinimalPermissionsPlugin.cs | Added Dispose override to clean up _apiCenterClient |
| DevProxy.Plugins/Mocking/MockResponsePlugin.cs | Added Dispose override to clean up _loader |
| DevProxy.Plugins/Mocking/MockRequestPlugin.cs | Refactored to use base class Dispose pattern instead of custom IDisposable implementation |
| DevProxy.Plugins/Mocking/CrudApiPlugin.cs | Added Dispose override to clean up _loader |
| DevProxy.Plugins/Manipulation/RewritePlugin.cs | Added Dispose override to clean up _loader |
| DevProxy.Plugins/Inspection/OpenAITelemetryPlugin.cs | Refactored to use base class Dispose pattern and clean up multiple resources |
| DevProxy.Plugins/Inspection/DevToolsPlugin.cs | Refactored to use base class Dispose pattern for _webSocket cleanup |
| DevProxy.Plugins/Guidance/GraphSelectGuidancePlugin.cs | Added Dispose override to clean up _msGraphDb |
| DevProxy.Plugins/Generation/ApiCenterOnboardingPlugin.cs | Added Dispose override to clean up _apiCenterClient |
| DevProxy.Plugins/Behavior/RateLimitingPlugin.cs | Added Dispose override to clean up _loader |
| DevProxy.Plugins/Behavior/LanguageModelRateLimitingPlugin.cs | Added Dispose override to clean up _loader |
| DevProxy.Plugins/Behavior/GenericRandomErrorPlugin.cs | Added Dispose override to clean up _loader |
Comments suppressed due to low confidence (1)
DevProxy/Proxy/ProxyEngine.cs:331
- The call to
ConfigFileWatcher.SignalProxyStopped()is inside a try-catch block that logs but swallows all exceptions. If an exception occurs before this line (e.g., during proxy cleanup), the signal will never be sent, causing the restart loop in Program.cs to hang indefinitely. Move theSignalProxyStopped()call to a finally block or ensure it's called in the catch block as well to guarantee it always executes.
private void StopProxy()
{
// Unsubscribe & Quit
try
{
_explicitEndPoint?.BeforeTunnelConnectRequest -= OnBeforeTunnelConnectRequestAsync;
if (ProxyServer is not null)
{
ProxyServer.BeforeRequest -= OnRequestAsync;
ProxyServer.BeforeResponse -= OnBeforeResponseAsync;
ProxyServer.AfterResponse -= OnAfterResponseAsync;
ProxyServer.ServerCertificateValidationCallback -= OnCertificateValidationAsync;
ProxyServer.ClientCertificateSelectionCallback -= OnCertificateSelectionAsync;
if (ProxyServer.ProxyRunning)
{
ProxyServer.Stop();
}
if (_explicitEndPoint != null && ProxyServer.ProxyEndPoints.Contains(_explicitEndPoint))
{
ProxyServer.RemoveEndPoint(_explicitEndPoint);
}
}
_inactivityTimer?.Stop();
if (RunTime.IsMac && _config.AsSystemProxy)
{
ToggleSystemProxy(ToggleSystemProxyAction.Off);
}
// Signal that proxy has fully stopped (including system proxy deregistration)
ConfigFileWatcher.SignalProxyStopped();
}
catch (Exception ex)
{
_logger.LogError(ex, "An error occurred while stopping the proxy");
}
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
garrytrinder
previously approved these changes
Jan 6, 2026
garrytrinder
approved these changes
Jan 8, 2026
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.

Adds support for configuration hot reload. Closes #247