title: Can't switch Upstream Proxy when Http Error occur
body: <h3>Problem Description</h3>
  <p>When I try to use <code>flow.live.change_upstream_proxy_server(address)</code> to switch the upstream Proxy in <code>Error()</code> method from <a href="https://docs.mitmproxy.org/master/addons-events/#http-events" rel="nofollow noreferrer">HttpEvents</a>, the upstream proxy stay the same and does not change.<br />
  I based my code on <a href="https://github.com/mitmproxy/mitmproxy/blob/master/examples/contrib/change_upstream_proxy.py" rel="nofollow noreferrer">this</a> example.</p>
  <h3>Steps to reproduce the behavior:</h3>
  <ol>
  <li>launch Mitm with an upstream and script:
  <code>mitmdump --mode upstream:182.52.74.76:34084 --ssl-insecure -s scripts/watcher.py</code></li>
  <li>wait for upstream proxy to fail</li>
  <li>let watcher.py renew the upstream proxy</li>
  </ol>
  <h3>Current result:</h3>
  <p>(can't post image directly due to lack of reputation)<br />
  <a href="https://i.imgur.com/vyz2bq3.png" rel="nofollow noreferrer">https://i.imgur.com/vyz2bq3.png</a></p>
  <p>At this point we assume that the upstream proxy is now changed to <code>103.199.84.54:8080</code>, but when we renew a request, we can see in the error message that the proxy is still the same (<code>182.52.74.76:34084</code>) instead of <code>103.199.84.54:8080</code> :</p>
  <p><a href="https://i.imgur.com/WkWFyBJ.png" rel="nofollow noreferrer">https://i.imgur.com/WkWFyBJ.png</a></p>
  <h3>Watcher.py</h3>
  <pre class="lang-py prettyprint-override"><code>from mitmproxy import http
  from mitmproxy import ctx
  
  import requests
  import json
  import typing
  
  #***** Some fetching to get new proxy from my API*****
  
  def getNewProxy() -&gt; typing.Tuple[str, int]:
      id = str(getRandID())
      params = { 'id': 'eq.' + id, 'select': 'proxy'}
      response = str(requests.get(url = url, params = params).json()[0]['proxy'])[7:].split(':')
      proxIP = (response[0], int(response[1]))
      return (proxIP)
  
  class Events:
      
      def error(self, flow: http.HTTPFlow):
          ctx.log.info(str(flow.server_conn.address))
          pAddr = getNewProxy()
          ctx.log.info(&quot;Switching upstream proxy to: &quot; + pAddr[0] + &quot;:&quot; + str(pAddr[1]))
          flow.live.change_upstream_proxy_server(pAddr)
  
  addons = [
      Events()
  ]
  
  </code></pre>
  <h3>System Information</h3>
  <p>mitmproxy --version:</p>
  <pre class="lang-sh prettyprint-override"><code>$ mitmdump --version
  Mitmproxy: 5.2
  Python:    3.7.3
  OpenSSL:   OpenSSL 1.1.1g  21 Apr 2020
  Platform:  Linux-4.19.0-9-amd64-x86_64-with-debian-10.4
  </code></pre>
  <p>Thanks for your help, really annoyed by this problem right now !</p>