Large Moodle downloads die prematurely when served through Varnish

Varnish and Moodle, to be blunt, hate each other. So much so that for my Moodle 1.9.x sites, I simply instruct Varnish to return(pass) without even trying to cache anything on a Moodle site. Today, however, I discovered even that is insufficient. Here’s what happened:

A user was reporting that when downloading large files from within Moodle (500mb course zip backups in this case), they’d stop at approximately 200mb. A look at varnishlog showed that Varnish was properly seeing that it’s a Moodle request that had a “Cache-Control: no-cache” header and didn’t even try to cache it before sending the request off to the backend. The backend was behaving exactly as expected and serving up the file. At some point, however, the download simply terminates before completion. No indications in the Varnish or Apache logs, nothing. It just … stops.

Huh.

So I put the following code in my VCL in vcl_recv:

if (req.url ~ "file.php") {
return (pipe);
}

Success!

Note: this must go into the VCL before the line in vcl_recv that checks the Cache-Control header, otherwise it’ll pass before it gets to the pipe:

if (req.url ~ "file.php") {
return (pipe);
}

# Force lookup if the request is a no-cache request from the client
if (req.http.Cache-Control ~ "no-cache") {
return (pass);
}

Share this:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Furl
  • Print
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis
  • Fark
  • LinkedIn
  • Ma.gnolia
  • NewsVine
  • Ping.fm
  • Pownce
  • Tumblr

2 Responses to “Large Moodle downloads die prematurely when served through Varnish”


  • Have you ever thought about including a little bit more than just your articles? I mean, what you say is valuable and everything. However just imagine if you added some great pictures or videos to give your posts more, “pop”! Your content is excellent but with images and clips, this blog could definitely be one of the very best in its niche. Wonderful blog!Raleigh Roofing, 3221 Durham Dr., #101-C, Raleigh, NC 27603 – (919) 701-6300

  • Just to let you know that I’m happy with text only. :)

Leave a Reply