title: The template could not be loaded. HTTP Status code: 0
body: <p><strong>Please read the question in full before answering.</strong></p>
  
  <p><strong>Problem Description:</strong> KnockoutJs is currently being used in our software for front-end templating. <em>Sometimes</em> a template request (xhr) doesn't get a and instead of the template appearing on the screen, the error: </p>
  
  <blockquote>
    <p>"The template could not be loaded. HTTP Status code: 0."</p>
  </blockquote>
  
  <p>is shown.  </p>
  
  <p><strong>Problem Details:</strong> </p>
  
  <ul>
  <li>This can happen to <em>Any, All or None</em> templates and the occurance seems to be random. </li>
  <li><p>I have seen the bug in both <em>Chrome and IE</em>, but not in Firefox. On Chrome it seems to be more common. </p></li>
  <li><p>The Status Code: 0 means that the request has not received a response, and this was confirmed in the network tab. </p></li>
  <li><p>Once this message is shown (and the request failed) for a specific template, every other request for the same template will fail whilst still in the same http session.</p></li>
  <li><p>This issue can be fixed in Chrome by opening <em>DevTools -> Network Tab</em> and checking the <em>disable cache</em> checkbox. </p></li>
  <li><p>The bug can be seen in an incognito browser and refreshing a page with <kbd>Ctrl</kbd>-<kbd>F5</kbd> doesn't seem to affect the bug, and doesn't fix it like the above point. </p></li>
  </ul>
  
  <p>It seems to be a caching issue, I know. Here is where it gets interesting.
  We looked at the HTTP and SSL information via the events page found in <code>chrome://net-internals</code> for the templates where the errors occured and we seen the following:</p>
  
  <p><strong>SSL Info:</strong></p>
  
  <pre><code>t=2156 [st= 0] +SOCKET_IN_USE  [dt=41]
                  --&gt; source_dependency = 4991 (HTTP_STREAM_JOB)
  t=2156 [st= 0]    SOCKET_BYTES_SENT
                    --&gt; byte_count = 957
  t=2156 [st= 0]    SSL_SOCKET_BYTES_SENT
                    --&gt; byte_count = 928
  t=2197 [st=41]    SOCKET_READ_ERROR
                    --&gt; net_error = -101 (ERR_CONNECTION_RESET)
                    --&gt; os_error = 10054
  t=2197 [st=41]    SSL_READ_ERROR
                    --&gt; error_lib = 33
                    --&gt; error_reason = 101
                    --&gt; file = "c:\\b\\c\\b\\win64_pgo\\src\\net\\socket\\socket_bio_adapter.cc"
                    --&gt; line = 107
                    --&gt; net_error = -101 (ERR_CONNECTION_RESET)
                    --&gt; ssl_error = 1
  t=2197 [st=41]    SOCKET_CLOSED
  t=2197 [st=41] -SOCKET_IN_USE
  t=2197 [st=41] -SOCKET_IN_USE
  t=2197 [st=41] -SOCKET_ALIVE
  </code></pre>
  
  <p>The socket_bio_adapter.cc file can be found <a href="https://chromium.googlesource.com/chromium/src/net/+/refs/heads/master/socket/socket_bio_adapter.cc" rel="nofollow noreferrer">here</a>.</p>
  
  <p><strong>HTTP info:</strong></p>
  
  <pre><code>...
  t=2076 [st=  1]     -HTTP_TRANSACTION_SEND_REQUEST
  t=2076 [st=  1]     +HTTP_TRANSACTION_READ_HEADERS  [dt=41]
  t=2076 [st=  1]        HTTP_STREAM_PARSER_READ_HEADERS  [dt=40]
                         --&gt; net_error = -101 (ERR_CONNECTION_RESET)
  t=2116 [st= 41]        HTTP_TRANSACTION_RESTART_AFTER_ERROR
                         --&gt; net_error = -101 (ERR_CONNECTION_RESET)
  t=2117 [st= 42]     -HTTP_TRANSACTION_READ_HEADERS
  t=2117 [st= 42]     +HTTP_STREAM_REQUEST  [dt=0]
  t=2117 [st= 42]        HTTP_STREAM_JOB_CONTROLLER_BOUND
                         --&gt; source_dependency = 4988 (HTTP_STREAM_JOB_CONTROLLER)
  t=2117 [st= 42]        HTTP_STREAM_REQUEST_BOUND_TO_JOB
                         --&gt; source_dependency = 4989 (HTTP_STREAM_JOB)
  t=2117 [st= 42]     -HTTP_STREAM_REQUEST
  ...
  </code></pre>
  
  <p>It seems to be more than just a caching issue but I don't understand how this SSL SOCKET_READ_ERROR can be related to and fixed by disabling the cache in the DevTools. </p>
  
  <p><strong>Technical Details:</strong></p>
  
  <pre><code>JQuery 2.2.4
  KnockoutJs 3.2.0
  TLS 1.2
  Chrome 58.0.3029.110 (64-bit)
  </code></pre>
  
  <p>I've researched the problem and have found countless resources, but none of them seem to directly apply to this specific issue. </p>
  
  <p><strong>Questions:</strong></p>
  
  <ul>
  <li><p>What is going on here? How can the cache be directly related to SSL? Or does it just seem that way? </p></li>
  <li><p>What woud clarify the sporadic nature of this issue? </p></li>
  </ul>
  
  <h2> Edit </h2>
  
  <p>I concluded that the requests that fail don't actually reach the application network. These requests are broken off client-side before they ever reach the backend landscape. </p>
  
  <p>This was fixed by adding two extra HTTP headers (Cache-Control: no-cache, Pragma:no-cache) to all template requests before they are sent. </p>
  
  <p>This fixes the problem but does not address the reason for it. Any insights into this problem is greatly appreciated. </p>