Shazwazza / ClientDependency

DEPRECATED. A library for managing CSS & JavaScript dependencies and optimization in ASP.Net
139 stars 65 forks source link

ClientDependency Directory does not exist #187

Closed PezCo closed 4 years ago

PezCo commented 4 years ago

I have an intermittent error were CSS does not load for a site via the dependency handler.

Console on chrome gives a generic: "Refused to apply style from 'https://example.com/DependencyHandler.axd?s=L2Nzcy9hcHAuY3NzOw&t=Css&cdv=2142871668' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled."

Hitting the URL directly gives: "Directory 'D:\local\Temp\UmbracoData\13978ceb9b0641fb41b12a5f518548dcc4707dfa\ClientDependency' does not exist. Failed to start monitoring file changes."

This site is on an azure web app, works locally. I have multiple slots with the same code that work fine, have tried deleting and recreating the slot to no avail.

Stack Trace

[HttpException (0x80070003): Directory 'D:\local\Temp\UmbracoData\13978ceb9b0641fb41b12a5f518548dcc4707dfa\ClientDependency' does not exist. Failed to start monitoring file changes.]
   System.Web.FileChangesMonitor.FindDirectoryMonitor(String dir, Boolean addIfNotFound, Boolean throwOnError) +251993620
   System.Web.FileChangesMonitor.StartMonitoringPath(String alias, FileChangeEventHandler callback, FileAttributesData& fad) +930
   System.Web.Caching.CacheDependency.Init(Boolean isPublic, String[] filenamesArg, String[] cachekeysArg, CacheDependency dependency, DateTime utcStart) +2680
   System.Web.Caching.CacheDependency..ctor(Int32 dummy, String[] filenames) +68
   System.Web.Caching.OutputCache.HasDependencyChanged(Boolean isFragment, String depKey, String[] fileDeps, String kernelKey, String oceKey, String providerName) +101
   System.Web.Caching.OutputCache.Get(String key) +114
   System.Web.Caching.OutputCacheModule.OnEnter(Object source, EventArgs eventArgs) +491
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +201
   System.Web.<>c__DisplayClass285_0.<ExecuteStepImpl>b__0() +26
   System.Web.StepInvoker.Invoke(Action executionStep) +100
   System.Web.<>c__DisplayClass4_0.<Invoke>b__0() +22
   Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule.OnExecuteRequestStep(HttpContextBase context, Action step) +65
   System.Web.<>c__DisplayClass284_0.<OnExecuteRequestStep>b__0(Action nextStepAction) +54
   System.Web.StepInvoker.Invoke(Action executionStep) +84
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73

ClientDependency version: 1.9.7 Umbraco Version: 7.15.3

Shazwazza commented 4 years ago

Hi, so is this stack trace from the dependency handler or where are you getting this stack trace from?

PezCo commented 4 years ago

Browser with <customErrors mode="Off"/> in the web.config when hitting the URL of the missing Client Dependancy file e.g 'https://example.com/DependencyHandler.axd?s=L2Nzcy9hcHAuY3NzOw&t=Css&cdv=2142871668' I dont think ive ever had the problem on a local development machine with same code which pushes me to thinking its an azure issue but i have followed all the Umbraco recommended steps for hosting on Azure.

Shazwazza commented 4 years ago

Yep i've never seen the issue either. Umbraco changes the location of CDF files to be in Azure %temp% (local) storage and this error is related to that since it's saying that the %temp% directory it's trying to access doesn't exist. Is this a one-off issue or can you replicate this issue?

PezCo commented 4 years ago

I wouldn't say one off, but i cant repeat it. I have 2 identical slots used for green blue deployment with azures swap function. the staging slot is almost permanently throwing the error, which persists after swap so we cant currently deploy using azure swap. other slots like a qa can sometimes get it intermittently but it usually rectifies by wither going to the umbraco admin or redeploying with a new client dependency number.

I dont know how azure slots work but deleting and recreating the slot had no affect.

Shazwazza commented 4 years ago

Very odd and definitely not seen the issue before. This is the code that configures CDF within Umbraco https://github.com/umbraco/Umbraco-CMS/blob/11f28554428390cf1e518c298e9959bd767020b5/src/Umbraco.Web/Runtime/WebInitialComponent.cs#L112 and this is the code that sets the %temp% path https://github.com/umbraco/Umbraco-CMS/blob/11f28554428390cf1e518c298e9959bd767020b5/src/Umbraco.Web/Runtime/WebInitialComponent.cs#L125

Each website regardless of slot swap has it's own %temp% path, they are different appdomains/processes. I wonder if in some zany way there's some timing issue where that folder isn't created before it tries reading/writing to it. In the code above the path is set to: Path.Combine(cachePath, "ClientDependency") but that code doesn't eagerly ensure that folder which could easily be done with Directory.CreateDirectory(cachePath). I'm fairly positive that CDF ensures this path itself else all sites would have this error but like i said maybe there's some unique situation that's preventing that from happening. The error is coming from aspnet's OutputCache so somehow maybe that handler is executing before CDF has ensured the path.

Perhaps you can try this and see if that fixes it?

PezCo commented 4 years ago

I think thats Umbraco V8 code you linked? Im in V7 for this bug sorry! 7.15.3 to be specific

PezCo commented 4 years ago

Whats strange is that if i go to url using the cdv thats in clientdependancy.config aka the one that gets rendered when using @Html.RenderCssHere() it doesn't work <clientDependency version="2142880001" fileDependencyExtensions=".js,.css" loggerType="Umbraco.Web.UI.CdfLogger, umbraco"> example.org/DependencyHandler.axd?s=L2Nzcy9hcHAuY3NzOw&t=Css&cdv=2142880001 - Broken

But i can change the cdv to any number i want in the browser and it returns the correct css

example.org/DependencyHandler.axd?s=L2Nzcy9hcHAuY3NzOw&t=Css&cdv=12345678 - Correct

Shazwazza commented 4 years ago

Sounds like that specific version has a bad state and it's been hard cached to disk. So if you change your config version to some other version you've never used before is everything fine again? You can also clear your temp CDF caches files at App_Data/TEMP/ClientDependency

I'll close this issue since there's not much else I can help with without steps to replicate.