# Buggy code
def do_CONNECT(self):
    # just provide a tunnel, transfer the data with no modification
    req = self
    req.path = "https://%s/" % req.path.replace(":443", "")

    u = urlsplit(req.path)
    address = (u.hostname, u.port or 443)
    try:
        conn = socket.create_connection(address)
    except socket.error as e:
        LOG.debug(
            "HTTPConnectProxyHandler: Got exception while trying to connect to %s: %s"
            % (repr(address), e)
        )
        self.send_error(504)  # 504 Gateway Timeout
        return
    self.send_response(200, "Connection Established")
    self.send_header("Connection", "close")
    self.end_headers()

    conns = [self.connection, conn]
    keep_connection = True
    while keep_connection:
        keep_connection = False
        rlist, wlist, xlist = select.select(conns, [], conns, self.timeout)
        if xlist:
            break
        for r in rlist:
            other = conns[1] if r is conns[0] else conns[0]
            data = r.recv(8192)
            if data:
                other.sendall(data)
                keep_connection = True
                update_last_serve_time()
    conn.close()


# Traceback (OSError)
2020-01-17 10:14:45,982 - iostream.py:1518 - _do_ssl_handshake() - WARNING - SSL Error on 1504 ('1.1.1.2', 4469): [SSL: NO_SHARED_CIPHER] no shared cipher (_ssl.c:1076)
2020-01-17 10:14:46,055 - iostream.py:1518 - _do_ssl_handshake() - WARNING - SSL Error on 1500 ('1.1.1.2', 4470): [SSL: VERSION_TOO_LOW] version too low (_ssl.c:1076)
2020-01-17 10:14:46,136 - iostream.py:744 - _handle_events() - ERROR - Uncaught exception, closing connection.
Traceback (most recent call last):
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 709, in _handle_events
self._handle_read()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 1581, in _handle_read
self._do_ssl_handshake()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 1501, in _do_ssl_handshake
self.socket.do_handshake()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error
2020-01-17 10:14:46,163 - base_events.py:1604 - default_exception_handler() - ERROR - Exception in callback None()
handle: <Handle cancelled>
Traceback (most recent call last):
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\asyncio\events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\platform\asyncio.py", line 122, in _handle_events
handler_func(fileobj, events)
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 709, in _handle_events
self._handle_read()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 1581, in _handle_read
self._do_ssl_handshake()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\site-packages\tornado\iostream.py", line 1501, in _do_ssl_handshake
self.socket.do_handshake()
File "C:\Users\Vakaris\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1139, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error

# Fixed code
def do_CONNECT(self):
    LOG.info("Received a connect request!")
    # just provide a tunnel, transfer the data with no modification
    req = self
    req.path = "https://%s/" % req.path.replace(":443", "")

    u = urlsplit(req.path)
    address = (u.hostname, u.port or 443)
    try:
        conn = socket.create_connection(address)
    except socket.error as e:
        LOG.debug(
            "HTTPConnectProxyHandler: Got exception while trying to connect to %s: %s"
            % (repr(address), e)
        )
        self.send_error(504)  # 504 Gateway Timeout
        return
    self.send_response(200, "Connection Established")
    self.send_header("Connection", "close")
    self.end_headers()

    conns = [self.connection, conn]
    keep_connection = True
    while keep_connection:
        keep_connection = False
        rlist, wlist, xlist = select.select(conns, [], conns, self.timeout)
        if xlist:
            break
        for r in rlist:
            other = conns[1] if r is conns[0] else conns[0]
            data = r.recv(8192)
            if data:
                other.sendall(data)
                keep_connection = True
                update_last_serve_time()
    conn.close()