Blank pages using Varnish 4.1 and Plone 5

Slightly off-topic, as it concerns Varnish, but still.

A warning: deployed a site using Plone 5, with some addons.

Nginx -> Varnish -> Plone (zeo).

Now, every now and again, visitors would get a blank page. Inspection with curl and firebug showed that Plone returned 304, as it should, but Varnish 4.1 would every now and again pass that on to the browser, instead of serving up the cached content. So, Varnish would return a 200, but with zero length.
With every now and then being the difficult part. Same browser, same system, might do it one in ten times. Other browser, other system, one in fifty times. Run curl two times, get different results.

Or, as is otherwise known, a "Heisenbug". The most obnoxious form of bug.

Tried a number of things, but the only solution that fixed it was revert to Varnish 4.0.3.

Noting this down for others as a warning, might save you some time.

Hello Paul,

That's good to know. Varnish can be a huge pain to debug, thakks for the effort. Which varnish.vcl are are you running where the blank pages occur?

It already happened using the standard one from http://docs.plone.org/manage/deploying/caching/varnish4.html, even the vanilla one without grace period and backend health checks.

Also added grace, added checks on beresp.http.Content-Length being zero or short-ish, and a lot of other things, but that's basically just trying to fix it by forcing a fresh, non-cached copy for every visitor that gets served badly by Varnish; hardly the point of caching.

As said before, Varnish 4.0 is behaving exactly as it should. So just be careful when upgrading.

Looks like this bug is fixed in 4.1.1:

Zero Content-Length is no longer sent on 304 responses.

Have you tried it with that release?

No, we're live and in the two most important weeks of the year now for the film festival, so not exactly the time for experiments. But yes, it does sound like exactly the bug.

@calvinhp Good catch!

For those who upgrade, this fix is not in 4.1.1 but in the just released 4.1.2 (added in 4.1.2-beta2 from the changelog Calvin linked to)