dukeofharen / httplaceholder

A very flexible cross platform HTTP stub application.
MIT License
109 stars 4 forks source link

bug: starting HttPlaceholder in folder with yaml files throws System.IO.FileNotFoundException #350

Closed nicobeemstergasunie closed 5 days ago

nicobeemstergasunie commented 1 month ago

Bug Report

HttPlaceholder version:

2024.2.24.160

Current behavior:

When starting HttPlaceholder in a folder with stubs defined in yaml-files, a System.IO.FileNotFoundException is thrown.

Log:

C:\stubs>httplaceholder -V
HttPlaceholder 2024.2.24.160 - (c) 2024 Ducode
Run this application with argument '-h' or '--help' to get more info about the command line arguments.
When running in to trouble, or just see what's going on, run this application with argument '-V' or '--verbose' to print the configuration variables.
You can also set the "verbose" environment variable (without quotes) to "true" to enable verbose logging.
    Visit https://httplaceholder.org/
Provided command line arguments: -V
Configuration that will be used by HttPlaceholder:
--Web:HttpPort: 5000
--Web:PfxPath: {path}
--Web:PfxPassword: {pw}
--Web:HttpsPort: 5050
--Web:UseHttps: True
--Gui:EnableUserInterface: True
--Storage:OldRequestsQueueLength: 40
--Stub:MaximumExtraDurationMillis: 60000
--Storage:CleanOldRequestsInBackgroundJob: True
--Storage:StoreResponses: False
--Web:ReadProxyHeaders: True
--Stub:AllowGlobalFileSearch: False
--Storage:FileStorageLocation: C:\stubs\.httplaceholder
--Logging:VerboseLoggingEnabled: True

2024-08-12 11:31:45.022 +02:00 [DBG] Hosting starting
2024-08-12 11:31:45.050 +02:00 [INF] User profile is available. Using '\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2024-08-12 11:31:45.157 +02:00 [DBG] New hosted service with name 'CleanOldRequestsJob' and schedule '*/5 * * * *' and the next occurrence will be on '8/12/2024 11:35:00 AM'
2024-08-12 11:31:45.206 +02:00 [INF] Available on http://127.0.0.1:5000
2024-08-12 11:31:45.207 +02:00 [INF] Available on http://localhost:5000
2024-08-12 11:31:45.208 +02:00 [INF] Available on http://10.132.23.14:5000
2024-08-12 11:31:47.671 +02:00 [INF] Available on https://127.0.0.1:5050
2024-08-12 11:31:47.672 +02:00 [INF] Available on https://localhost:5050
2024-08-12 11:31:47.673 +02:00 [INF] Available on https://10.132.23.14:5050
2024-08-12 11:31:47.683 +02:00 [DBG] Reading data from file '\AppData\Local\ASP.NET\DataProtection-Keys\key-{Guid}.xml'.
2024-08-12 11:31:47.694 +02:00 [DBG] Found key {Guid}.
2024-08-12 11:31:47.704 +02:00 [DBG] Considering key {Guid} with expiration date 2024-10-24 09:56:03Z as default key.
2024-08-12 11:31:47.707 +02:00 [DBG] Forwarded activator type request from Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlDecryptor, Microsoft.AspNetCore.DataProtection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 to Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlDecryptor, Microsoft.AspNetCore.DataProtection, Culture=neutral, PublicKeyToken=adb9793829ddae60
2024-08-12 11:31:47.709 +02:00 [DBG] Decrypting secret element using Windows DPAPI.
2024-08-12 11:31:47.712 +02:00 [DBG] Forwarded activator type request from Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 to Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Culture=neutral, PublicKeyToken=adb9793829ddae60
2024-08-12 11:31:47.716 +02:00 [DBG] Opening CNG algorithm 'AES' from provider 'null' with chaining mode CBC.
2024-08-12 11:31:47.718 +02:00 [DBG] Opening CNG algorithm 'SHA256' from provider 'null' with HMAC.
2024-08-12 11:31:47.720 +02:00 [DBG] Using key {Guid} as the default key.
2024-08-12 11:31:47.722 +02:00 [DBG] Key ring with default key {Guid} was loaded during application startup.
2024-08-12 11:31:47.824 +02:00 [FTL] Application startup exception
System.IO.FileNotFoundException: Error reading the  directory.
   at System.IO.FileSystemWatcher.StartRaisingEvents()
   at HttPlaceholder.Infrastructure.Implementations.FileWatchers.FileWatcherBuilder..ctor(IFileService fileService) in /app/src/HttPlaceholder.Infrastructure/Implementations/FileWatchers/FileWatcherBuilder.cs:line 11
   at HttPlaceholder.Infrastructure.Implementations.FileWatchers.FileWatcherBuilderFactory.CreateBuilder() in /app/src/HttPlaceholder.Infrastructure/Implementations/FileWatchers/FileWatcherBuilderFactory.cs:line 9
   at HttPlaceholder.Persistence.Implementations.StubSources.FileWatcherYamlFileStubSource.SetupWatcherForLocation(String location) in /app/src/HttPlaceholder.Persistence/Implementations/StubSources/FileWatcherYamlFileStubSource.cs:line 128
   at HttPlaceholder.Persistence.Implementations.StubSources.FileWatcherYamlFileStubSource.SetupStubs() in /app/src/HttPlaceholder.Persistence/Implementations/StubSources/FileWatcherYamlFileStubSource.cs:line 99
   at HttPlaceholder.Persistence.Implementations.StubSources.FileWatcherYamlFileStubSource.PrepareStubSourceAsync(CancellationToken cancellationToken) in /app/src/HttPlaceholder.Persistence/Implementations/StubSources/FileWatcherYamlFileStubSource.cs:line 66
   at HttPlaceholder.Application.StubExecution.Implementations.StubContext.<>c__DisplayClass29_0.<PrepareAsync>b__0(IStubSource s) in /app/src/HttPlaceholder.Application/StubExecution/Implementations/StubContext.cs:line 274
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Threading.Tasks.Task.WhenAll(IEnumerable`1 tasks)
   at HttPlaceholder.Application.StubExecution.Implementations.StubContext.PrepareAsync(CancellationToken cancellationToken) in /app/src/HttPlaceholder.Application/StubExecution/Implementations/StubContext.cs:line 274
   at HttPlaceholder.Web.Shared.Utilities.StartupUtilities.PreloadStubs(IApplicationBuilder app, Boolean preloadStubs) in /app/src/HttPlaceholder.Web.Shared/Utilities/StartupUtilities.cs:line 94
   at HttPlaceholder.Web.Shared.BaseStartup.Configure(IApplicationBuilder app, Boolean preloadStubs, SettingsModel settings) in /app/src/HttPlaceholder.Web.Shared/BaseStartup.cs:line 23
   at HttPlaceholder.Startup.ConfigureStatic(IApplicationBuilder app, Boolean preloadStubs, SettingsModel settings) in /app/src/HttPlaceholder/Startup.cs:line 50
   at HttPlaceholder.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in /app/src/HttPlaceholder/Startup.cs:line 41
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
2024-08-12 11:31:47.866 +02:00 [DBG] Initializing the cache, because either the local stub cache or tracking ID is not set yet.
2024-08-12 11:31:47.872 +02:00 [ERR] Hosting failed to start
System.IO.FileNotFoundException: Error reading the  directory.
   at System.IO.FileSystemWatcher.StartRaisingEvents()
   at HttPlaceholder.Infrastructure.Implementations.FileWatchers.FileWatcherBuilder..ctor(IFileService fileService) in /app/src/HttPlaceholder.Infrastructure/Implementations/FileWatchers/FileWatcherBuilder.cs:line 11
   at HttPlaceholder.Infrastructure.Implementations.FileWatchers.FileWatcherBuilderFactory.CreateBuilder() in /app/src/HttPlaceholder.Infrastructure/Implementations/FileWatchers/FileWatcherBuilderFactory.cs:line 9
   at HttPlaceholder.Persistence.Implementations.StubSources.FileWatcherYamlFileStubSource.SetupWatcherForLocation(String location) in /app/src/HttPlaceholder.Persistence/Implementations/StubSources/FileWatcherYamlFileStubSource.cs:line 128
   at HttPlaceholder.Persistence.Implementations.StubSources.FileWatcherYamlFileStubSource.SetupStubs() in /app/src/HttPlaceholder.Persistence/Implementations/StubSources/FileWatcherYamlFileStubSource.cs:line 99
   at HttPlaceholder.Persistence.Implementations.StubSources.FileWatcherYamlFileStubSource.PrepareStubSourceAsync(CancellationToken cancellationToken) in /app/src/HttPlaceholder.Persistence/Implementations/StubSources/FileWatcherYamlFileStubSource.cs:line 66
   at HttPlaceholder.Application.StubExecution.Implementations.StubContext.<>c__DisplayClass29_0.<PrepareAsync>b__0(IStubSource s) in /app/src/HttPlaceholder.Application/StubExecution/Implementations/StubContext.cs:line 274
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Threading.Tasks.Task.WhenAll(IEnumerable`1 tasks)
   at HttPlaceholder.Application.StubExecution.Implementations.StubContext.PrepareAsync(CancellationToken cancellationToken) in /app/src/HttPlaceholder.Application/StubExecution/Implementations/StubContext.cs:line 274
   at HttPlaceholder.Web.Shared.Utilities.StartupUtilities.PreloadStubs(IApplicationBuilder app, Boolean preloadStubs) in /app/src/HttPlaceholder.Web.Shared/Utilities/StartupUtilities.cs:line 94
   at HttPlaceholder.Web.Shared.BaseStartup.Configure(IApplicationBuilder app, Boolean preloadStubs, SettingsModel settings) in /app/src/HttPlaceholder.Web.Shared/BaseStartup.cs:line 23
   at HttPlaceholder.Startup.ConfigureStatic(IApplicationBuilder app, Boolean preloadStubs, SettingsModel settings) in /app/src/HttPlaceholder/Startup.cs:line 50
   at HttPlaceholder.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in /app/src/HttPlaceholder/Startup.cs:line 41
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)
   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
2024-08-12 11:31:47.883 +02:00 [FTL] Host terminated unexpectedly
System.IO.FileNotFoundException: Error reading the  directory.
   at System.IO.FileSystemWatcher.StartRaisingEvents()
   at HttPlaceholder.Infrastructure.Implementations.FileWatchers.FileWatcherBuilder..ctor(IFileService fileService) in /app/src/HttPlaceholder.Infrastructure/Implementations/FileWatchers/FileWatcherBuilder.cs:line 11
   at HttPlaceholder.Infrastructure.Implementations.FileWatchers.FileWatcherBuilderFactory.CreateBuilder() in /app/src/HttPlaceholder.Infrastructure/Implementations/FileWatchers/FileWatcherBuilderFactory.cs:line 9
   at HttPlaceholder.Persistence.Implementations.StubSources.FileWatcherYamlFileStubSource.SetupWatcherForLocation(String location) in /app/src/HttPlaceholder.Persistence/Implementations/StubSources/FileWatcherYamlFileStubSource.cs:line 128
   at HttPlaceholder.Persistence.Implementations.StubSources.FileWatcherYamlFileStubSource.SetupStubs() in /app/src/HttPlaceholder.Persistence/Implementations/StubSources/FileWatcherYamlFileStubSource.cs:line 99
   at HttPlaceholder.Persistence.Implementations.StubSources.FileWatcherYamlFileStubSource.PrepareStubSourceAsync(CancellationToken cancellationToken) in /app/src/HttPlaceholder.Persistence/Implementations/StubSources/FileWatcherYamlFileStubSource.cs:line 66
   at HttPlaceholder.Application.StubExecution.Implementations.StubContext.<>c__DisplayClass29_0.<PrepareAsync>b__0(IStubSource s) in /app/src/HttPlaceholder.Application/StubExecution/Implementations/StubContext.cs:line 274
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Threading.Tasks.Task.WhenAll(IEnumerable`1 tasks)
   at HttPlaceholder.Application.StubExecution.Implementations.StubContext.PrepareAsync(CancellationToken cancellationToken) in /app/src/HttPlaceholder.Application/StubExecution/Implementations/StubContext.cs:line 274
   at HttPlaceholder.Web.Shared.Utilities.StartupUtilities.PreloadStubs(IApplicationBuilder app, Boolean preloadStubs) in /app/src/HttPlaceholder.Web.Shared/Utilities/StartupUtilities.cs:line 94
   at HttPlaceholder.Web.Shared.BaseStartup.Configure(IApplicationBuilder app, Boolean preloadStubs, SettingsModel settings) in /app/src/HttPlaceholder.Web.Shared/BaseStartup.cs:line 23
   at HttPlaceholder.Startup.ConfigureStatic(IApplicationBuilder app, Boolean preloadStubs, SettingsModel settings) in /app/src/HttPlaceholder/Startup.cs:line 50
   at HttPlaceholder.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in /app/src/HttPlaceholder/Startup.cs:line 41
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token)
   at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
   at HttPlaceholder.Program.Main(String[] args) in /app/src/HttPlaceholder/Program.cs:line 21

Expected behavior:

HttPlaceholder should start successfully and load the stubs defined in the directory.

Steps to reproduce:

Other information:

Running HttPlaceholder from an empty folder (not containing any stubs) and manually importing the stubs does work.

OS

Edition Windows 11 Enterprise
Version 23H2
OS build    22631.3880

.NET versions

.NET SDK:
 Version:           8.0.303
 Commit:            29ab8e3268
 Workload version:  8.0.300-manifests.7ccdde63
 MSBuild version:   17.10.4+10fbfbf2e

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.303\

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.7
  Architecture: x64
  Commit:       2aade6beb0

.NET SDKs installed:
  8.0.107 [C:\Program Files\dotnet\sdk]
  8.0.303 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found
dukeofharen commented 1 month ago

@nicobeemstergasunie thanks for the bug report. This is a strange one... I have to dive into this problem a bit more. I recently built functionality for HttPlaceholder to use file watchers, it seems this is causing the issue somehow on Windows. Can you try disabling the file watcher and see if it works then? https://github.com/dukeofharen/httplaceholder/blob/master/docs/docs.md#disable-file-watcher

nicobeemstergasunie commented 1 month ago

Thanks for the quick reply. Disabling the file watcher indeed works!

dukeofharen commented 3 weeks ago

Apparently there was a bug in initializing the FileWatcher class. Initializing the class with settings in another order fixes the problem apparently. A fix will be coming soon.

dukeofharen commented 5 days ago

A new release has been pushed which contains this fix: https://github.com/dukeofharen/httplaceholder/releases/tag/v2024.9.7.8