nopSolutions / nopCommerce

ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
https://www.nopcommerce.com
Other
9.19k stars 5.28k forks source link

System.IO.FileNotFoundException: Unable to find the specified file - Bundling process #5817

Closed egachi closed 2 years ago

egachi commented 3 years ago

nopCommerce version: 4.3.0.0

Environment:

Steps to reproduce the problem: Issue is randomly happening without any code changes or deployments, it can happen after a restart. We can't reproduce the issue in another environment (same configurations and code), it is just happening in production, the only difference can be request load.

System.IO.FileNotFoundException: Unable to find the specified file.    
at Interop.Sys.GetCwdHelper(Byte* ptr, Int32 bufferSize)    
at Interop.Sys.GetCwd()    
at BundlerMinifier.FileHelpers.NormalizePath(String path)    
at BundlerMinifier.Bundle.GetAbsoluteInputFiles(Boolean notifyOnPatternMiss)    
at BundlerMinifier.BundleFileProcessor.ProcessBundle(String baseFolder, Bundle bundle)    
at BundlerMinifier.BundleFileProcessor.Process(String fileName, IEnumerable`1 bundles)    
at Nop.Web.Framework.UI. PageHeadBuilder.GenerateCssFiles (ResourceLocation location, Nullable`1 bundleFiles) in D:\a\1\s\Presentation\Nop.Web.Framework\UI\PageHeadBuilder.cs:line 654    
at Nop.Web.Framework.UI.LayoutExtensions.NopCssFiles(IHtmlHelper html, ResourceLocation location, Nullable`1 bundleFiles) in D:\a\1\s\Presentation\Nop.Web.Framework\UI\LayoutExtensions.cs:line 284    at AspNetCore.Views_Shared__Root_Head.<>c__DisplayClass9_0.<<ExecuteAsync>b__0>d.MoveNext() in D:\a\1\s\Presentation\Nop.Web\Views\Shared\_Root.Head.cshtml:line 76 --- End of stack trace from previous location where exception was thrown ---    at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.SetOutputContentAsync()    at AspNetCore.Views_Shared__Root_Head.ExecuteAsync() in D:\a\1\s\Presentation\Nop.Web\Views\Shared\_Root.Head.cshtml:line 53    at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)    at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)    at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderLayoutAsync(ViewContext context, ViewBufferTextWriter bodyWriter)    at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)    
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)    
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)    
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)    
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)    
at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)    
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultAsync>g__Logged|21_0(ResourceInvoker invoker, IActionResult result)    
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)    
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)    
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)    
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters() --- End of stack trace from previous location where exception was thrown ---    
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)    
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)    
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)    
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location where exception was thrown ---    
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)    
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)    
at WebMarkupMin.AspNetCore3.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, Boolean useMinification, Boolean useCompression)    
at WebMarkupMin.AspNetCore3.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, Boolean useMinification, Boolean useCompression)    
at WebMarkupMin.AspNetCore3.WebMarkupMinMiddlewareBase.Invoke(HttpContext context)    
at Nop.Services.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) in D:\a\1\s\Libraries\Nop.Services\Authentication\AuthenticationMiddleware.cs:line 79    
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)    
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)    
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)    
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)    
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)    
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)    
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)    
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)    
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)    
at Nop.Services.Common.KeepAliveMiddleware.Invoke(HttpContext context, IWebHelper webHelper) in D:\a\1\s\Libraries\Nop.Services\Common\KeepAliveMiddleware.cs:line 50    
at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.Invoke(HttpContext context)    
at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)    
at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)    
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

I see several threads with bundling not working as expected in Linux:

• Css bundling not working · Issue #3440 · nopSolutions/nopCommerce (github.com) • Bundling minification on linux · Issue #4135 · nopSolutions/nopCommerce (github.com)

Checking further on the BundlerMinifier library, there are some validations for Linux or Windows urls file path locations based on the current directory. https://github.com/madskristensen/BundlerMinifier/blob/master/src/BundlerMinifier.Core/Helpers/FileHelpers.cs#L74

There is a possibility that in certain conditions the path changes since using a Windows File Share and ending into a different path format which it can be complaining but this is just a theory.

Are you aware of any possible issue when using .NET core 3.1 with docker and mounting application files under a Windows File Share?

Any insights will be appreciate.

Thanks

egachi commented 3 years ago

Do you think adding extra logging on this part can help us to get the complete path and see if there are any issue with the format?

//Public declaration 
Nop.Services.Logging.DefaultLogger _logger = (Nop.Services.Logging.DefaultLogger)Nop.Core.Infrastructure.EngineContext.Current.Resolve<Nop.Services.Logging.ILogger>();

//Inside GenerateCssFiles() method...
 lock (_lock)
     {
         //store json file to see a generated config file (for debugging purposes)
         //BundleHandler.AddBundle(configFilePath, bundle);

        //process
        //custom logging event...
        _logger.InsertLog(Nop.Core.Domain.Logging.LogLevel.Information, "Debugging: Checking ConfigFilePath !", "Date:" + DateTime.Now.ToString() + "ConfigFilePath: " + configFilePath.ToString(), null);
        _processor.Process(configFilePath, new List<Bundle> {bundle});
      }
exileDev commented 2 years ago

We couldn't reproduce it. If you find any conditions that can help to reproduce the issue, we'll reopen it.

Closed #5817