From: rs <> Date: Sat, 20 Dec 2025 01:45:57 +0000 (-0600) Subject: Catch exception during handshake with client X-Git-Url: https://git.the-white-hart.net/?a=commitdiff_plain;h=f2eb33793bbc3769f61852d17152814fc2782719;p=gemini%2Fcbs-server.git Catch exception during handshake with client When Lagrange doesn't yet trust the server's cert, it hangs up the connection during the handshake phase, which causes OpenSSL to raise a SysCallError. Catch this, log it, and continue to serve normally afterwards. --- diff --git a/cbs-srv.py b/cbs-srv.py index 2778b37..e252ad9 100755 --- a/cbs-srv.py +++ b/cbs-srv.py @@ -221,20 +221,27 @@ def main(): ssock = SSL.Connection(ctxt, sock) ssock.set_accept_state() while True: - conn, addr = ssock.accept() - conn.do_handshake() - logging.info('Connection from {}'.format(addr)) try: + conn, addr = ssock.accept() + conn.do_handshake() + logging.info('Connection from {}'.format(addr)) req = recv_req(conn) serve_req(conn, addr, req, conf) + conn.shutdown() + conn.sock_shutdown(socket.SHUT_RDWR) + except SSL.SysCallError as x: + logging.error('{}'.format(x)) + # Don't call conn.shutdown or sock_shutdown except CBSException as x: logging.error('{} {} {}'.format(x.code, x.meta, x.logdata)) conn.sendall('{} {}\r\n'.format(x.code, x.meta).encode('utf-8')) + conn.shutdown() + conn.sock_shutdown(socket.SHUT_RDWR) except Exception as x: logging.error('Exception: {}'.format(x)) conn.sendall('40 Server error\r\n'.encode('utf-8')) - conn.shutdown() - conn.sock_shutdown(socket.SHUT_RDWR) + conn.shutdown() + conn.sock_shutdown(socket.SHUT_RDWR) if __name__ == '__main__':