Intermittent 502 errors with version 3.0.3

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

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

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
← Server disconnected GET http://removed-url/favicon.ico
← Server disconnected

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?

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.

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.

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

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

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