title: Magento Checkout Place Order button redirects to empty cart page when Varnish is active
body: <p>I have a setup that includes Magento 1.9, Nginx, Varnish 3. Clicking "Place Order" button on onepage checkout redirects to empty cart page instead of success page. It happens only in case of REGISTER checkout method. In case of logged in customer checkout works fine. </p>
  
  <p>Also regardless of the type of checkout method, order placed has all data saved and accurate in admin.</p>
  
  <p>What I've observed so far is that the redirect is happening in the OnepageController::successAction() itself at this code part.</p>
  
  <pre><code>$session = $this-&gt;getOnepage()-&gt;getCheckout();
  if (!$session-&gt;getLastSuccessQuoteId()) {
      $this-&gt;_redirect('checkout/cart');
      return;
  }  
  </code></pre>
  
  <p><code>$session-&gt;getLastSuccessQuoteId()</code> returns <code>null</code>. In fact the whole session got cleared unexpectedely before this line got executed. </p>
  
  <p>The reason why I feel it's related to Varnish is that it happens only when Varnish is active.</p>
  
  <p>What can be the possible debug steps for this session issue when varnish is involved?</p>
  
  <p><strong>location:</strong> /etc/sysconfig/varnish</p>
  
  <pre><code># Configuration file for varnish
  #
  # /etc/init.d/varnish expects the variable $DAEMON_OPTS to be set from this
  # shell script fragment.
  #
  
  # Maximum number of open files (for ulimit -n)
  NFILES=131072
  
  # Locked shared memory (for ulimit -l)
  # Default log size is 82MB + header
  MEMLOCK=82000
  
  # Maximum number of threads (for ulimit -u)
  NPROCS="unlimited"
  
  # Maximum size of corefile (for ulimit -c). Default in Fedora is 0
  # DAEMON_COREFILE_LIMIT="unlimited"
  
  # Set this to 1 to make init script reload try to switch vcl without restart.
  # To make this work, you need to set the following variables
  # explicit: VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_ADDRESS,
  # VARNISH_ADMIN_LISTEN_PORT, VARNISH_SECRET_FILE, or in short,
  # use Alternative 3, Advanced configuration, below
  RELOAD_VCL=1
  
  # This file contains 4 alternatives, please use only one.
  
  ## Alternative 1, Minimal configuration, no VCL
  #
  # Listen on port 6081, administration on localhost:6082, and forward to
  # content server on localhost:8080.  Use a fixed-size cache file.
  #
  #DAEMON_OPTS="-a :6081 \
  #             -T localhost:6082 \
  #             -b localhost:8080 \
  #             -u varnish -g varnish \
  #             -s file,/var/lib/varnish/varnish_storage.bin,1G"
  
  
  ## Alternative 2, Configuration with VCL
  #
  # Listen on port 6081, administration on localhost:6082, and forward to
  # one content server selected by the vcl file, based on the request.  Use a
  # fixed-size cache file.
  #
  #DAEMON_OPTS="-a :6081 \
  #             -T localhost:6082 \
  #             -f /etc/varnish/default.vcl \
  #             -u varnish -g varnish \
  #             -S /etc/varnish/secret \
  #             -s file,/var/lib/varnish/varnish_storage.bin,1G"
  
  ## Alternative 3, Advanced configuration
  #
  # See varnishd(1) for more information.
  #
  # # Main configuration file. You probably want to change it :)
  VARNISH_VCL_CONF=/etc/varnish/default.vcl
  #
  # # Default address and port to bind to
  # # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
  # # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
  # VARNISH_LISTEN_ADDRESS=
  VARNISH_LISTEN_PORT=6081
  #
  # # Telnet admin interface listen address and port
  VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
  VARNISH_ADMIN_LISTEN_PORT=6082
  #
  # # Shared secret file for admin interface
  VARNISH_SECRET_FILE=/etc/varnish/secret
  #
  # # The minimum number of worker threads to start
  VARNISH_MIN_THREADS=50
  #
  # # The Maximum number of worker threads to start
  VARNISH_MAX_THREADS=1000
  #
  # # Idle timeout for worker threads
  VARNISH_THREAD_TIMEOUT=120
  #
  # # Cache file size: in bytes, optionally using k / M / G / T suffix,
  # # or in percentage of available disk space using the % suffix.
  VARNISH_STORAGE_SIZE=256M
  #
  # # Backend storage specification
  VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"
  #
  # # Backend storage specification
  VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"
  #
  # # Default TTL used when the backend does not specify one
  VARNISH_TTL=120
  #
  # # DAEMON_OPTS is used by the init script.  If you add or remove options, make
  # # sure you update this section, too.
  DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
               -f ${VARNISH_VCL_CONF} \
               -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
               -t ${VARNISH_TTL} \
               -p thread_pool_min=${VARNISH_MIN_THREADS} \
               -p thread_pool_max=${VARNISH_MAX_THREADS} \
               -p thread_pool_timeout=${VARNISH_THREAD_TIMEOUT} \
               -u varnish -g varnish \
               -S ${VARNISH_SECRET_FILE} \
               -s ${VARNISH_STORAGE}"
  #
  
  
  ## Alternative 4, Do It Yourself. See varnishd(1) for more information.
  #
  # DAEMON_OPTS=""
  </code></pre>
  
  <p><strong>location:</strong> /etc/varnish/default.vcl</p>
  
  <pre><code>#
  # This is an example VCL file for Varnish.
  #
  # It does not do anything by default, delegating control to the
  # builtin VCL. The builtin VCL is called when there is no explicit
  # return statement.
  #
  # See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
  # and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.
  
  # Marker to tell the VCL compiler that this VCL has been adapted to the
  # new 4.0 format.
  vcl 4.0;
  
  # Default backend definition. Set this to point to your content server.
  backend default {
      .host = "127.0.0.1";
      .port = "8080";
  }
  
  sub vcl_recv {
      # Happens before we check if we have this in cache already.
      #
      # Typically you clean up the request here, removing cookies you don't need,
      # rewriting the request, etc.
  }
  
  sub vcl_backend_response {
      # Happens after we have read the response headers from the backend.
      #
      # Here you clean the response headers, removing silly Set-Cookie headers
      # and other mistakes your backend does.
  }
  
  sub vcl_deliver {
      # Happens when we have all the pieces we need, and are about to send the
      # response to the client.
      #
      # You can do accounting or modifying the final object here.
  }
  </code></pre>