Golang : ExecuteTemplate results in errror: `write tcp 127.0.0.1:8080->127.0.0.1:35212: write: broken pipe` with multiple requests
<p>I have something like this:</p>

<pre><code>t, err1 := template.ParseFiles("exampleFile.tmpl")
if err1 != nil {
    panic(err1)
}
err2 := t.ExecuteTemplate(w, "example", someStruct)
if err2 != nil {
    panic(err2)
}
</code></pre>

<p>With simple requests, there are no problems. </p>

<p>But if I send two requests very close to each other, about 40% of the time from simple page refreshes from Chrome and a few ajax requests, it results in various different errors (err2): </p>

<ul>
<li><code>write tcp 127.0.0.1:8080-&gt;127.0.0.1:35212: write: broken pipe</code></li>
<li><code>write: connection reset by peer</code></li>
<li><code>use of closed network connection</code></li>
<li><code>http: panic serving 127.0.0.1:35814: runtime error: slice bounds out of range
goroutine 340 (...)</code></li>
</ul>

<p>Others seem to have had similar issues, but with no clear resolution.  </p>

<ul>
<li><a href="https://stackoverflow.com/questions/26853200/filter-out-broken-pipe-errors-from-template-execution">Filter out broken pipe errors from template execution</a></li>
<li><a href="https://groups.google.com/forum/#!topic/golang-nuts/g6UNu4Mrv28" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/golang-nuts/g6UNu4Mrv28</a></li>
</ul>

<p>Another post seems to suggest just to expect this, and retry failed requests:</p>

<ul>
<li><a href="https://stackoverflow.com/a/31409281/1923095">https://stackoverflow.com/a/31409281/1923095</a></li>
</ul>

<p>What's the best Golang way to handle this?  </p>