Skip to content
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

PhysicalFilesWatcher: Log file/path triggering a change notification #100872

Open
CodeBlanch opened this issue Apr 10, 2024 · 1 comment
Open

Comments

@CodeBlanch
Copy link
Contributor

I'm working with a user reporting a bug in OpenTelemetry .NET. It seems some file system change is triggering an IConfiguration reload which is manifesting a bug in OpenTelemetry causing some resources to be created (background threads) which aren't ever used or cleaned up. We're fixing that bug in OpenTelemetry but so far we haven't been able to figure out why that configuration reload is firing.

In the call stack we see:

Microsoft.Extensions.FileProviders.Physical.dll!Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher..cctor.AnonymousMethod__43_0(object state) Line 29	C#
  • User is on .NET 6.
  • User is calling Host.CreateDefaultBuilder(args) to create their host.
  • User isn't using any appSettings.json files.

I'm wondering if we could add some EventSource info/verbose logging inside PhysicalFilesWatcher to help troubleshoot issues in the future.

OTel issue: open-telemetry/opentelemetry-dotnet#5513

More of the stack trace
        ...user portion removed...
 	Microsoft.Extensions.Options.dll!Microsoft.Extensions.Options.ConfigureNamedOptions<System.__Canon>.Configure(string name, System.__Canon options) Line 49	C#
 	Microsoft.Extensions.Options.dll!Microsoft.Extensions.Options.OptionsFactory<OpenTelemetry.Logs.OpenTelemetryLoggerOptions>.Create(string name) Line 87	C#
 	Microsoft.Extensions.Options.dll!Microsoft.Extensions.Options.OptionsMonitor<OpenTelemetry.Logs.OpenTelemetryLoggerOptions>.Get.AnonymousMethod__10_0(string name, Microsoft.Extensions.Options.IOptionsFactory<OpenTelemetry.Logs.OpenTelemetryLoggerOptions> factory) Line 94	C#
 	Microsoft.Extensions.Options.dll!Microsoft.Extensions.Options.OptionsCache<System.__Canon>.GetOrAdd.AnonymousMethod__2() Line 68	C#
 	System.Private.CoreLib.dll!System.Lazy<OpenTelemetry.Logs.OpenTelemetryLoggerOptions>.ViaFactory(System.Threading.LazyThreadSafetyMode mode) Line 321	C#
 	System.Private.CoreLib.dll!System.Lazy<OpenTelemetry.Logs.OpenTelemetryLoggerOptions>.ExecutionAndPublication(System.LazyHelper executionAndPublication, bool useDefaultConstructor) Line 345	C#
 	System.Private.CoreLib.dll!System.Lazy<OpenTelemetry.Logs.OpenTelemetryLoggerOptions>.CreateValue() Line 433	C#
 	System.Private.CoreLib.dll!System.Lazy<System.__Canon>.Value.get() Line 505	C#
 	Microsoft.Extensions.Options.dll!Microsoft.Extensions.Options.OptionsCache<OpenTelemetry.Logs.OpenTelemetryLoggerOptions>.GetOrAdd<Microsoft.Extensions.Options.IOptionsFactory<OpenTelemetry.Logs.OpenTelemetryLoggerOptions>>(string name, System.Func<string, Microsoft.Extensions.Options.IOptionsFactory<OpenTelemetry.Logs.OpenTelemetryLoggerOptions>, OpenTelemetry.Logs.OpenTelemetryLoggerOptions> createOptions, Microsoft.Extensions.Options.IOptionsFactory<OpenTelemetry.Logs.OpenTelemetryLoggerOptions> factoryArgument) Line 66	C#
 	Microsoft.Extensions.Options.dll!Microsoft.Extensions.Options.OptionsMonitor<OpenTelemetry.Logs.OpenTelemetryLoggerOptions>.Get(string name) Line 94	C#
 	Microsoft.Extensions.Options.dll!Microsoft.Extensions.Options.OptionsMonitor<OpenTelemetry.Logs.OpenTelemetryLoggerOptions>.InvokeChanged(string name) Line 68	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<string>.OnChangeTokenFired() Line 87	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<string>.RegisterChangeTokenCallback.AnonymousMethod__7_0(object s) Line 103	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.Invoke(System.Delegate d, object state, System.Threading.CancellationTokenSource source) Line 902	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.CallbackNode.ExecuteCallback.AnonymousMethod__9_0(object s) Line 1139	C#
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 183	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.CallbackNode.ExecuteCallback() Line 1141	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(bool throwOnFirstException) Line 722	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.NotifyCancellation(bool throwOnFirstException) Line 639	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.Cancel() Line 221	C#
 	Microsoft.Extensions.Configuration.dll!Microsoft.Extensions.Configuration.ConfigurationReloadToken.OnReload() Line 41	C#
 	Microsoft.Extensions.Configuration.dll!Microsoft.Extensions.Configuration.ConfigurationRoot.RaiseChanged() Line 93	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.OnChange.AnonymousMethod__0_0(System.Action callback) Line 32	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<System.Action>.OnChangeTokenFired() Line 87	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<System.Action>.RegisterChangeTokenCallback.AnonymousMethod__7_0(object s) Line 103	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.Invoke(System.Delegate d, object state, System.Threading.CancellationTokenSource source) Line 902	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.CallbackNode.ExecuteCallback.AnonymousMethod__9_0(object s) Line 1139	C#
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 183	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.CallbackNode.ExecuteCallback() Line 1141	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(bool throwOnFirstException) Line 722	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.NotifyCancellation(bool throwOnFirstException) Line 639	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.Cancel() Line 221	C#
 	Microsoft.Extensions.Configuration.dll!Microsoft.Extensions.Configuration.ConfigurationReloadToken.OnReload() Line 41	C#
 	Microsoft.Extensions.Configuration.dll!Microsoft.Extensions.Configuration.ConfigurationRoot.RaiseChanged() Line 93	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.OnChange.AnonymousMethod__0_0(System.Action callback) Line 32	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<System.Action>.OnChangeTokenFired() Line 87	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<System.Action>.RegisterChangeTokenCallback.AnonymousMethod__7_0(object s) Line 103	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.Invoke(System.Delegate d, object state, System.Threading.CancellationTokenSource source) Line 902	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.CallbackNode.ExecuteCallback.AnonymousMethod__9_0(object s) Line 1139	C#
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 183	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.CallbackNode.ExecuteCallback() Line 1141	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(bool throwOnFirstException) Line 722	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.NotifyCancellation(bool throwOnFirstException) Line 639	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.Cancel() Line 221	C#
 	Microsoft.Extensions.Configuration.dll!Microsoft.Extensions.Configuration.ConfigurationReloadToken.OnReload() Line 41	C#
 	Microsoft.Extensions.Configuration.dll!Microsoft.Extensions.Configuration.ConfigurationProvider.OnReload() Line 118	C#
 	Microsoft.Extensions.Configuration.FileExtensions.dll!Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(bool reload) Line 113	C#
 	Microsoft.Extensions.Configuration.FileExtensions.dll!Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor.AnonymousMethod__1_1() Line 40	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.OnChange.AnonymousMethod__0_0(System.Action callback) Line 32	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<System.Action>.OnChangeTokenFired() Line 87	C#
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<System.Action>.RegisterChangeTokenCallback.AnonymousMethod__7_0(object s) Line 103	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.Invoke(System.Delegate d, object state, System.Threading.CancellationTokenSource source) Line 902	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.CallbackNode.ExecuteCallback() Line 1141	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(bool throwOnFirstException) Line 722	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.NotifyCancellation(bool throwOnFirstException) Line 639	C#
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.Cancel() Line 221	C#
>	Microsoft.Extensions.FileProviders.Physical.dll!Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher..cctor.AnonymousMethod__43_0(object state) Line 29	C#
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.InnerInvoke() Line 2397	C#
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task..cctor.AnonymousMethod__272_0(object obj) Line 2376	C#
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread threadPoolThread, System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 268	C#
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread) Line 2337	C#
 	System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteEntryUnsafe(System.Threading.Thread threadPoolThread) Line 2277	C#
 	System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Line 790	C#
 	System.Private.CoreLib.dll!System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() Line 63	C#
 	System.Private.CoreLib.dll!System.Threading.Thread.StartCallback() Line 106	C#
 	[Native to Managed Transition]	

/cc @tarekgh

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Apr 10, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 10, 2024
@vcsjones vcsjones added area-Extensions-Configuration and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Apr 10, 2024
@jozkee
Copy link
Member

jozkee commented Jul 3, 2024

That method you are seeing seems to be spawned when a change token matches a path reported by the underlying FileSystemWatcher. I wonder if its possible that the PhysicalFilesWatcher is being disposed before the thread finish execution, not sure if that would cause problems.
What's the error message?
Do you have a consoleapp repro?

@jozkee jozkee removed the untriaged New issue has not been triaged by the area owner label Jul 3, 2024
@jozkee jozkee added this to the Future milestone Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants