# Server side SSL client socket after socket.accept() gets no socket timeout (issue in Lib/ssl.py#L1390) # # Steps to reproduce: # 1. Generate self-signed certificates using commandline: # openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365 # 2. Launch this script: # python3 https.py # 3. Launch client ghost script: # python3 ghost.py # 4. Expected: # Client ghost successfully connects to server and is disconnected after 2 seconds client timeout # Actual: # Client ghost successfully connects to server and keeps hanging on after 2 seconds timeout has passed import http.server import ssl print("https begin serving...") httpd = http.server.ThreadingHTTPServer(("0.0.0.0", 443), http.server.BaseHTTPRequestHandler) httpd.socket.settimeout(2) # << setting socket timeout on TCP socket # simple context ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) ctx.verify_mode = ssl.CERT_REQUIRED ctx.check_hostname = False ctx.load_default_certs() ctx.load_cert_chain(certfile='./cert.pem', keyfile='./key.pem', password=None) httpd.socket = ctx.wrap_socket(httpd.socket,server_side=True) httpd.socket.settimeout(2) # << setting socket timeout on SSL socket httpd.serve_forever() print("done")