Shazwazza / Smidge

A lightweight runtime CSS/JavaScript file minification, combination, compression & management library for ASP.Net Core
MIT License
364 stars 47 forks source link

Attempting to add items to the in memory directory multiple times #183

Open dc-durable opened 1 year ago

dc-durable commented 1 year ago

Hello,

I'm sorry there's not a huge amount to go on here as I couldn't recreate the issue locally, but using Smidge with Umbraco it looks like there are occasions where System.InvalidOperationException: Cannot add item to the directory, as an item with the same name already exists. is thrown when bundling. Having looked through the source, I can see in SmidgeController.cs a todo related to locking which may be related if Bundle is being called by multiple clients simultaneously?

My stack trace from the logs looks like this:

System.InvalidOperationException: Cannot add item to the directory, as an item with the same name already exists. at Dazinator.Extensions.FileProviders.InMemory.Directory.FolderDirectoryItem.AddFile(IFileInfo file) at Dazinator.Extensions.FileProviders.InMemory.Directory.InMemoryDirectory.AddFile(String folderPath, IFileInfo file) at Smidge.InMemory.MemoryCacheFileSystem.WriteFileAsync(String filePath, Stream contents) at Smidge.Controllers.SmidgeController.CacheCompositeFileAsync(ICacheFileSystem cacheProvider, String filePath, Stream compositeStream) at Smidge.Controllers.SmidgeController.Bundle(BundleRequestModel bundleModel) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|25_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.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) ... (outputs from other middleware)

Happy to answer any questions. Thank you.

gurgendav commented 4 months ago

I'm experiencing the same problem. @dc-durable have you been able to solve this somehow?