Parsing complex CSS can fail, leaving cache in an inconsistent state. #1092
Comments
@jeffkaufman I just tested out #1068 with v1.9.32.6. "Works in Chrome but not in Firefox' issue is fixed. But I still see the flattening css issue. If you try out http://www.enjoy-swimming.sbi2b.sitesell.com you'll see that the page is broken because of the css rewrite fail. Happy to assist if you need anything from me to get this issue fixed. |
Have you cleared your cache since upgrading? I think you may still have an (incorrectly) empty resource in cache from the previous version. https://developers.google.com/speed/pagespeed/module/system#flush_cache |
I did. I went in and deleted everything in the cache directory, just to be sure. I still see the issue. |
Did you also touch cache.flush? Or did you delete things while pagespeed wasn't running? Simply deleting things while pagespeed is running isn't enough because pagespeed does some in-memory caching. |
Purged entire cache via pagespeed admin. I can still see it happening. Its random though. Only certain rewrites fail. |
Ok, thanks! @oschaaf would you be able to look into this? It sounds like empty resources are not being fully excluded, and we could either fix that here or by fixing the way we handle flattening failing. |
@jeffkaufman I'll look into it |
I need to set up a repro to confirm, but I suspect this fixes #1092
Still looking into this. Observations so far:
A similar byte sequence seems to get stored in cache for the resource:
Perhaps the byte order mark is the reason that 8f93d5c didn't prevent the issue here as it it looks like the content here is non-zero length due to the byte order mark. |
This minimal patch passes tests, and fixes the issue: diff --git a/net/instaweb/rewriter/public/css_flatten_imports_context.h b/net/instaweb/rewriter/public/css_flatten_imports_context.h
index d60b8fd..f7cec85 100644
--- a/net/instaweb/rewriter/public/css_flatten_imports_context.h
+++ b/net/instaweb/rewriter/public/css_flatten_imports_context.h
@@ -186,6 +186,9 @@ class CssFlattenImportsContext : public SingleRewriteContext {
hierarchy_->set_minified_contents(
output_partition(0)->inlined_data());
hierarchy_->set_input_contents(hierarchy_->minified_contents());
+ // Parse() will compute flattening_succeeded_, which needs to be restored
+ // See https://github.com/pagespeed/mod_pagespeed/issues/1092
+ hierarchy_->Parse();
}
} else {
// Something has gone wrong earlier. It could be that the resource is @jeffkaufman what do you think, would this be acceptable performance-wise? Or would it be better to persist state in cache for the |
When does this code run? Just when optimizing the resource, right? In which case the performance implications should be minimal. Can we verify that there's no way to get into this on a per-request basis? |
@jeffkaufman I tested manually earlier, and the code only fired when optimizing the resource. |
Yes, this sounds good. A test and PR sound great! |
In
CssHierarchy::RollUpContents
, ifminified_contents_
was set externally, withoutParse()
running, then it's possible it contains something incompatible with flattening. The problem is something like
flattening_failed_
not being saved in our cache. This was causing #1068, but then 8f93d5c fixed that, so I don't think this is visible externally, but our css filter is still doing something incorrect.The text was updated successfully, but these errors were encountered: