From: Daniel McCarney Date: Wed, 8 Apr 2026 20:28:06 +0000 (-0400) Subject: tests/http: add abrupt server close test X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;p=thirdparty%2Fcurl.git tests/http: add abrupt server close test Test that connecting to a server that immediately closes the connection produces an error instead of hanging/timing out. --- diff --git a/tests/http/test_05_errors.py b/tests/http/test_05_errors.py index 7a64e3055d..c50310404f 100644 --- a/tests/http/test_05_errors.py +++ b/tests/http/test_05_errors.py @@ -26,6 +26,8 @@ # import logging import os +import socket +import threading import pytest from testenv import CurlClient, Env @@ -179,3 +181,34 @@ class TestErrors: r.check_response(http_status=401) # No retries on a 401 assert r.stats[0]['num_retries'] == 0, f'{r}' + + # Server closes the connection immediately after accept, + def test_05_09_handshake_eof(self, env: Env, httpd, nghttpx): + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server: + server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + server.bind(('127.0.0.1', 0)) + server.listen(1) + port = server.getsockname()[1] + + # accept one connection and immediately close it + def accept_and_close(): + try: + conn, _ = server.accept() + conn.close() + except Exception: + pass + + t = threading.Thread(target=accept_and_close) + t.start() + + curl = CurlClient(env=env, timeout=5) + url = f'https://127.0.0.1:{port}/' + r = curl.run_direct(args=[url, '--insecure']) + + t.join(timeout=2) + + # We expect an error code, not success (0) and not timeout (-1) + # Expected error code is: + # - CURLE_SSL_CONNECT_ERROR (35) - common for handshake failures + assert r.exit_code == 35, \ + f'Expected error 35, got {r.exit_code}\n{r.dump_logs()}'