# Intermittent 502 errors with version 3.0.3

**URL:** <https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939>\
**Category:** help\
**Created:** [March 24, 2018, 7:03am UTC](https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939 "2018-03-24T07:03:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@Anton](https://discourse.mitmproxy.org/u/Anton)\
**Post date:** [March 24, 2018, 7:03am UTC](https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939/1 "2018-03-24T07:03:29Z")

</div>

Hi All,

I am seeing intermittent errors when using mitmproxy 3.0.3. The error is always:  
502 Bad Gateway  
HttpReadDisconnect(‘Server disconnected’,).

I installed mitmproxy 2.0.2 via pip to test, and have never received this error when using version 2. Immediately switching back to 3.0.3 causes the error to reappear (on the same web sites). The python version for both is 3.6.4 and its running in Arch linux.

Does anyone know why this might be happening, or have any troubleshooting suggestions?

Thanks in advance,  
Anton

---

<div class="post-metadata">

**Author:** ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)\
**Post date:** [March 24, 2018, 8:12pm UTC](https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939/2 "2018-03-24T20:12:00Z")

</div>

Do you see anything in the event log that looks off?

---

<div class="post-metadata">

**Author:** ![Anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@Anton](https://discourse.mitmproxy.org/u/Anton)\
**Post date:** [March 25, 2018, 10:16am UTC](https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939/3 "2018-03-25T10:16:28Z")

</div>

The only entries that seem to coincide are the clientdisconnect messages in the log, and the Server disconnected messages in the console:  
Log-  
info: 127.0.0.1:33094: clientconnect  
info: 127.0.0.1:33094: clientdisconnect  
info: 127.0.0.1:33096: clientconnect  
info: 127.0.0.1:33064: clientdisconnect  
info: 127.0.0.1:33074: clientdisconnect

Console-  
GET [http://removed-url/challenges](http://removed-url/challenges)  
← Server disconnected GET [http://removed-url/favicon.ico](http://removed-url/favicon.ico)  
← Server disconnected

---

<div class="post-metadata">

**Author:** ![Anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@Anton](https://discourse.mitmproxy.org/u/Anton)\
**Post date:** [March 26, 2018, 11:05pm UTC](https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939/4 "2018-03-26T23:05:11Z")

</div>

Additionally, I did disable http2 with ‘mitmproxy --no-http2’, however the errors kept occurring. Often if I refresh the page a few times it eventually works. Also, this is happening to a few people in my team, the same errors, so its not limited to my machine.

Is there a way of turning on more verbose logging (debug style) to see what the underlying problem is?

---

<div class="post-metadata">

**Author:** ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)\
**Post date:** [March 27, 2018, 12:36pm UTC](https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939/5 "2018-03-27T12:36:39Z")

</div>

You can turn on debug logs using `-v`. I believe this may be the same issue as in [https://github.com/mitmproxy/mitmproxy/issues/3003](https://github.com/mitmproxy/mitmproxy/issues/3003).

---

<div class="post-metadata">

**Author:** ![paskyorg](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/paskyorg/32/61_2.png) [@paskyorg](https://discourse.mitmproxy.org/u/paskyorg)\
**Post date:** [March 29, 2018, 4:32pm UTC](https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939/6 "2018-03-29T16:32:35Z")

</div>

I get this error too with mitmdump 3.0.3. It seems that the problem occurs when I’m idle about one minute.

With `-v` I don’t see any problem.

I modified \_read\_response\_line(rfile) function on read.py file, to debug with pdb:

```
def _read_response_line(rfile):
    import pdb
    try:
        line = _get_first_line(rfile)
    except exceptions.HttpReadDisconnect:
        pdb.set_trace()
        # We want to provide a better error message.
        raise exceptions.HttpReadDisconnect("Server disconnected")

```

And debug:

```
 (Pdb) w
c:\program files (x86)\python36-32\lib\threading.py(884)_bootstrap()
-> self._bootstrap_inner()
  c:\program files (x86)\python36-32\lib\threading.py(916)_bootstrap_inner()
-> self.run()
  c:\program files (x86)\python36-32\lib\threading.py(864)run()
-> self._target(*self._args, **self._kwargs)
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\net\tcp.py(589)connection_thread()
-> self.handle_client_connection(connection, client_address)
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\server.py(68)handle_client_connection()
-> h.handle()
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\server.py(121)handle()
-> root_layer()
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\modes\http_proxy.py(9) __call__ ()
-> layer()
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\protocol\tls.py(286) __call__ ()
-> layer()
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\protocol\http1.py(83) __call__ ()
-> layer()
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\protocol\http.py(188) __call__ ()
-> if not self._process_flow(flow):
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\protocol\http.py(260)_process_flow()
-> return self.handle_regular_connect(f)
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\protocol\http.py(206)handle_regular_connect()
-> layer()
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\protocol\tls.py(286) __call__ ()
-> layer()
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\protocol\http1.py(83) __call__ ()
-> layer()
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\protocol\http.py(188) __call__ ()
-> if not self._process_flow(flow):
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\protocol\http.py(375)_process_flow()
-> f.response = self.read_response_headers()
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\proxy\protocol\http1.py(41)read_response_headers()
-> resp = http1.read_response_head(self.server_conn.rfile)
  c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\net\http\http1\read.py(92)read_response_head()
-> http_version, status_code, message = _read_response_line(rfile)
> c:\users\user\envs\mitmproxy303\lib\site-packages\mitmproxy\net\http\http1\read.py(297)_read_response_line()
-> raise exceptions.HttpReadDisconnect("Server disconnected")

```

Sorry, but I don’t know debug so much inside mitmproxy.

---

<div class="post-metadata">

**Author:** ![Anton](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@Anton](https://discourse.mitmproxy.org/u/Anton)\
**Post date:** [April 4, 2018, 12:47am UTC](https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939/7 "2018-04-04T00:47:24Z")

</div>

Hi All - Any updates on issue 3003? Last I saw was from Alekseynp.

---

<div class="post-metadata">

**Author:** ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)\
**Post date:** [April 5, 2018, 11:52am UTC](https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939/8 "2018-04-05T11:52:01Z")

</div>

Looking at this again this more likely is the same problem as in [https://github.com/mitmproxy/mitmproxy/issues/3038](https://github.com/mitmproxy/mitmproxy/issues/3038).

---

<div class="post-metadata">

**Author:** ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)\
**Post date:** [April 5, 2018, 4:04pm UTC](https://discourse.mitmproxy.org/t/intermittent-502-errors-with-version-3-0-3/939/9 "2018-04-05T16:04:01Z")

</div>

Hi, we just released mitmproxy 3.0.4 - I believe this should fix this issue! 😃
