Repository: mitmproxy/mitmproxy

Issue:
Crash from comparison with None
#### Problem Description

I got this crash after leaving mitmproxy open for a few hours:

```
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/server.py", line 121, in handle
    root_layer()-laptop ~]$ 
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/modes/http_proxy.py", line 9, in __call__
    layer()oking-laptop ~]$ 
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/protocol/tls.py", line 285, in __call__
    layer()
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/protocol/http1.py", line 83, in __call__
    layer()
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/protocol/http.py", line 190, in __call__
    if not self._process_flow(flow):
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/protocol/http.py", line 262, in _process_flow
    return self.handle_regular_connect(f)
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/protocol/http.py", line 208, in handle_regular_connect
    layer()
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/protocol/tls.py", line 285, in __call__
    layer()
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/protocol/http1.py", line 83, in __call__
    layer()
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/protocol/http.py", line 190, in __call__
    if not self._process_flow(flow):
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/protocol/http.py", line 244, in _process_flow
    request = self.read_request_headers(f)
  File "/usr/lib/python3.8/site-packages/mitmproxy/proxy/protocol/http1.py", line 15, in read_request_headers
    http1.read_request_head(self.client_conn.rfile)
  File "/usr/lib/python3.8/site-packages/mitmproxy/net/http/http1/read.py", line 54, in read_request_head
    form, method, scheme, host, port, path, http_version = _read_request_line(rfile)
  File "/usr/lib/python3.8/site-packages/mitmproxy/net/http/http1/read.py", line 245, in _read_request_line
    line = _get_first_line(rfile)
  File "/usr/lib/python3.8/site-packages/mitmproxy/net/http/http1/read.py", line 232, in _get_first_line
    line = rfile.readline()
  File "/usr/lib/python3.8/site-packages/mitmproxy/net/tcp.py", line 158, in readline
    ch = self.read(1)
  File "/usr/lib/python3.8/site-packages/mitmproxy/net/tcp.py", line 128, in read
    if (time.time() - start) < self.o.gettimeout():
TypeError: '<' not supported between instances of 'float' and 'NoneType'
```

I use mitmproxy almost every day and this is the first time it happens.

#### Steps to reproduce the behavior:
No clue.

#### System Information

Mitmproxy: 5.1.1
Python:    3.8.3
OpenSSL:   OpenSSL 1.1.1g  21 Apr 2020
Platform:  Linux-5.6.15-arch1-1-x86_64-with-glibc2.2.5



Discussion:

Resolving patch:
diff --git a/mitmproxy/net/tcp.py b/mitmproxy/net/tcp.py
--- a/mitmproxy/net/tcp.py
+++ b/mitmproxy/net/tcp.py
@@ -125,7 +125,9 @@ def read(self, length):
                 # underlying BIO could not satisfy the needs of SSL_read() to continue the
                 # operation. In this case a call to SSL_get_error with the return value of
                 # SSL_read() will yield SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
-                if (time.time() - start) < self.o.gettimeout():
+                # 300 is OpenSSL default timeout
+                timeout = self.o.gettimeout() or 300
+                if (time.time() - start) < timeout:
                     time.sleep(0.1)
                     continue
                 else:


Test patch: