mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
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.
This commit is contained in:
parent
ce05754c7c
commit
0a7e1982fe
@ -26,6 +26,8 @@
|
|||||||
#
|
#
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import socket
|
||||||
|
import threading
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from testenv import CurlClient, Env
|
from testenv import CurlClient, Env
|
||||||
@ -179,3 +181,34 @@ class TestErrors:
|
|||||||
r.check_response(http_status=401)
|
r.check_response(http_status=401)
|
||||||
# No retries on a 401
|
# No retries on a 401
|
||||||
assert r.stats[0]['num_retries'] == 0, f'{r}'
|
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()}'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user