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

System.IO.IOException: The process cannot access the file "path/to/file" because it is being used by another process #210

Closed
PeterKvayt opened this issue Jul 24, 2024 · 4 comments · Fixed by #211
Labels

Comments

@PeterKvayt
Copy link

PeterKvayt commented Jul 24, 2024

I use umbraco 10.8.2, which is use Smidge 4.2.1

I faced with following exception: An unhandled exception has occurred while executing the request.

System.IO.IOException: The process cannot access the file 'C:\home\site\wwwroot\Smidge\Cache\{machine name}\92ee6281ad3366850c9d45e154f82540c3cbee8a\gzip\umbraco-backoffice-js.s' because it is being used by another process.
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
at System.IO.File.Create(String path)
at Smidge.Cache.PhysicalFileCacheFileSystem.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.g__Awaited|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.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|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.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
(stack trace skipped)

This exception was thrown during executing two or more requests which triggered "/sb/umbraco-backoffice-js.js.v92ee6281ad3366850c9d45e154f82540c3cbee8a" url. This url is Bundle action.

As i can see to fix it we should to implement sort lock here or as alternative solution start using polly to retry creating a cache on exception.

@Shazwazza Shazwazza added the bug label Jul 24, 2024
@Shazwazza
Copy link
Owner

Yep looks like you hit a race condition issue. A quick solution would be to add a lock in the Smidge.Cache.PhysicalFileCacheFileSystem.WriteFileAsync

Also, looking at the path it is erroring on, there's a configuration bug occurring somewhere:

C:\home\site\wwwroot\Smidge\Cache{nachine name}\92ee6281ad3366850c9d45e154f82540c3cbee8a\gzip\umbraco-backoffice-js.s

... the {nachine name} part is not right and I'm not sure where that is coming from.

I'll look into adding a lock now.

@Shazwazza
Copy link
Owner

@PeterKvayt Can you please review #211?

@PeterKvayt
Copy link
Author

PeterKvayt commented Jul 25, 2024

@Shazwazza Thanks for the fast reply. I will review your fix when I have free time.

... the {nachine name} part is not right and I'm not sure where that is coming from.

It was a typo. I have fixed the original comment.

@Shazwazza
Copy link
Owner

I am going to go ahead and merge this, local and unit tests are passing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants