diff --git a/.github/workflows/kernel-e2e.yml b/.github/workflows/kernel-e2e.yml index 5a2dac03b..8a240a5d8 100644 --- a/.github/workflows/kernel-e2e.yml +++ b/.github/workflows/kernel-e2e.yml @@ -351,6 +351,11 @@ jobs: - name: Run async reader routing tests run: $CONNECTOR_VENV_PY -m pytest tests/unit/test_kernel_async_readers.py -m realkernel -v + - name: Run real-kernel session tests (port loopback dials) + # Published wheels without the `port` kwarg skip these, so run them + # against the wheel built from KERNEL_REV. + run: $CONNECTOR_VENV_PY -m pytest tests/unit/test_session.py -m realkernel -v + - name: Run kernel e2e tests run: poetry run pytest tests/e2e/test_kernel_backend.py -v diff --git a/CHANGELOG.md b/CHANGELOG.md index 43fda3bed..c31d6927f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Release History # Unreleased +- Honor `_port` and `_connection_uri` on kernel connections (`use_kernel=True`), as Thrift does. Requires a databricks-sql-kernel release that includes databricks/databricks-sql-kernel#505. - Speed up `fetchone()`, `fetchmany()` and `fetchall()` by building each result `Row` with fewer Python calls. The rows are unchanged. Large results and many concurrent cursors in one process benefit most. # 4.10.0 (2026-11-24) diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index f0b3d2ee7..6d4f336fd 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -73,8 +73,8 @@ to change without notice. | ----------------- | ----- | :----: | :----: | ------------- | ----------------------------------------------------------------------------------------------------------------------- | | `server_hostname` | `str` | ✅ | ✅ | — (required) | Workspace hostname, e.g. `dbc-12345.cloud.databricks.com`. | | `http_path` | `str` | ✅ | ✅ | — (required) | Thrift accepts a SQL-warehouse path **or** an all-purpose-cluster path; Kernel requires a warehouse/endpoint path. | -| `_port` | `int` | ✅ | — | `443` | TCP port (advanced). Not threaded to the kernel; it derives host/port from `server_hostname` + `http_path`. | -| `_connection_uri` | `str` | ✅ | — | `None` | Thrift-only internal override of `server_hostname`/`http_path`. No kernel equivalent. | +| `_port` | `int` | ✅ | ✅ | `443` | TCP port (advanced). A digit string such as `"8443"` is accepted as that int. On Kernel it is passed to the kernel, which validates and applies it: a port other than 443 makes the connection use `host:port`; `0`, unset and `443` change nothing; a non-default port embedded in `server_hostname` wins over a differing `_port` (with a warning). An IPv6 host needs brackets (`[::1]`). An invalid port raises `OperationalError` (wrapping the kernel's `ValueError`); a host that can't take the port raises `ProgrammingError`, and the error never repeats the host. Needs a databricks-sql-kernel release that includes databricks-sql-kernel#505. | +| `_connection_uri` | `str` | ✅ | ✅ | `None` | Overrides `server_hostname`, `_port` and `http_path` on both, and wins over `_port`. On Kernel, OAuth also uses the URI's host:port (Thrift keeps OAuth on `server_hostname`). Credentials in the URI are rejected. | | `http_headers` | `List[Tuple[str, str]]` | ✅ | ⚠️ | `None` | Extra headers sent on requests. Kernel filters `Authorization` and `x-databricks-org-id` because it manages them itself; other headers are forwarded. | | `user_agent_entry`| `str` | ✅ | ✅ | `None` | Custom tag folded into the composed `User-Agent` on both. (`_user_agent_entry` is a deprecated alias that warns.) | @@ -213,8 +213,7 @@ are forwarded when supported by the installed kernel binding. `_retry_dangerous_codes`, `_respect_server_retry_after_header`, `_retry_max_redirects`, `_enable_v3_retries`. 8. `force_enable_telemetry`. -9. `_port` and `_connection_uri`. -10. `_pool_connections` and `_proxy_auth_method` do not configure the +9. `_pool_connections` and `_proxy_auth_method` do not configure the kernel-owned network stack. ### Supported on Kernel, missing / ignored on Thrift diff --git a/KERNEL_REV b/KERNEL_REV index 2add322e2..101d21c5a 100644 --- a/KERNEL_REV +++ b/KERNEL_REV @@ -1 +1 @@ -5c3a909771f749174567af074bfe18c24a335f5c +3b691d2a2c235ef847d61b308c31604979830994 diff --git a/src/databricks/sql/backend/kernel/client.py b/src/databricks/sql/backend/kernel/client.py index eab9847ca..a0e77bbc7 100644 --- a/src/databricks/sql/backend/kernel/client.py +++ b/src/databricks/sql/backend/kernel/client.py @@ -321,10 +321,12 @@ def __init__( # toggles, mTLS client cert/key). ``http_headers`` is forwarded # to the kernel as custom request headers (it carries the # connector's composed ``User-Agent`` + any caller headers + the - # SPOG ``x-databricks-org-id``). ``http_client`` / ``port`` are - # still accept-and-ignore — the kernel manages its own HTTP - # stack. + # SPOG ``x-databricks-org-id``). ``port`` (the resolved ``_port``, + # or ``None``) is forwarded as the kernel's ``port`` kwarg, which + # the kernel applies to ``server_hostname``. ``http_client`` is + # accept-and-ignore — the kernel manages its own HTTP stack. self._server_hostname = server_hostname + self._port: Any = kwargs.get("port") self._http_path = http_path self._auth_provider = auth_provider self._ssl_options = ssl_options @@ -488,6 +490,15 @@ def open_session( geospatial_kwargs = _kernel_geospatial_kwargs( self._enable_geospatial_support ) + # The kernel validates the port and applies it to the host; unset sends nothing. + port_kwargs: Dict[str, Any] = {} + if self._port is not None: + if not _kernel_session_accepts_kwarg("port"): + raise NotSupportedError( + "_port requires a newer databricks-sql-kernel wheel " + "that accepts a connection port." + ) + port_kwargs["port"] = self._port max_connections_kwargs: Dict[str, Any] = {} if _kernel_session_accepts_kwarg("max_connections"): max_connections_kwargs["max_connections"] = self._max_connections @@ -536,6 +547,7 @@ def open_session( **retry_kwargs, **telemetry_kwargs, **geospatial_kwargs, + **port_kwargs, **max_connections_kwargs, **http_headers_kwargs, ) diff --git a/src/databricks/sql/client.py b/src/databricks/sql/client.py index d8240efaf..15db8f8f9 100755 --- a/src/databricks/sql/client.py +++ b/src/databricks/sql/client.py @@ -193,6 +193,10 @@ def __init__( decision. This is an intentional divergence from the Thrift/SEA paths, where an explicit ``True`` can still be suppressed by the feature flag. + + Kernel overrides: _port is passed to the kernel, which applies it to + the host. _connection_uri (https://host[:port]/path?query) sets host, + port, path and query, as on Thrift, and wins over _port. :param enable_geospatial_support: `bool`, optional (default is False) Kernel backend only. Controls the public representation of ``GEOMETRY`` and ``GEOGRAPHY`` result values. ``True`` returns diff --git a/src/databricks/sql/session.py b/src/databricks/sql/session.py index cd91693d3..1f98cc674 100644 --- a/src/databricks/sql/session.py +++ b/src/databricks/sql/session.py @@ -1,6 +1,7 @@ import logging import re from functools import cached_property +from urllib.parse import urlsplit from typing import Dict, Tuple, List, Optional, Any, Type, TYPE_CHECKING from databricks.sql.types import SSLOptions @@ -47,6 +48,31 @@ def __getattr__(name: str) -> Any: raise AttributeError(f"module {__name__!r} has no attribute {name!r}") +def _kernel_endpoint( + server_hostname: str, http_path: str, kwargs: dict +) -> Tuple[str, str, Any]: + """Resolve the kernel ``(host, http_path, port)``. ``_connection_uri`` gives the host + (with any port in it) and the path, and wins over ``_port``. Otherwise the arguments + pass through as is; the kernel validates the port and applies it to the host. + """ + uri = kwargs.get("_connection_uri") + if not uri: + port = kwargs.get("_port") + # A digit string (e.g. from an env var or DSN) becomes the int it names, as Thrift + # accepts it. This is type coercion only; any other value reaches the kernel as is. + if isinstance(port, str) and port.strip().isascii() and port.strip().isdigit(): + port = int(port) + return server_hostname, http_path, port + parts = urlsplit(uri) + # Credentials in the URI would reach the transport, so they are refused here. + if parts.scheme not in ("http", "https") or not parts.netloc or "@" in parts.netloc: + raise ValueError( + "Invalid _connection_uri: expected http(s)://host[:port]/path with no credentials" + ) + path = parts.path + (f"?{parts.query}" if parts.query else "") + return f"{parts.scheme}://{parts.netloc}", path, None + + class Session: def __init__( self, @@ -323,9 +349,23 @@ def _create_backend( "_telemetry_circuit_breaker_enabled" ), } + kernel_host, kernel_http_path, kernel_port = _kernel_endpoint( + server_hostname, http_path, kwargs + ) + if kernel_http_path != http_path: + # A _connection_uri can point at another workspace: re-derive the + # SPOG org-id header from the resolved path (a caller header still wins). + base_headers = [ + h for h in all_headers if h not in self._spog_headers.items() + ] + self._spog_headers = self._extract_spog_headers( + kernel_http_path, base_headers + ) + all_headers = base_headers + list(self._spog_headers.items()) return KernelDatabricksClient( - server_hostname=server_hostname, - http_path=http_path, + server_hostname=kernel_host, + http_path=kernel_http_path, + port=kernel_port, http_headers=all_headers, auth_provider=auth_provider, ssl_options=self.ssl_options, diff --git a/tests/unit/test_kernel_client.py b/tests/unit/test_kernel_client.py index 5bad2040b..ded4a3362 100644 --- a/tests/unit/test_kernel_client.py +++ b/tests/unit/test_kernel_client.py @@ -541,6 +541,70 @@ def test_geospatial_option_rejects_non_bool(): kernel_client._kernel_geospatial_kwargs("false") +@pytest.mark.parametrize("port", [8443, 443, 0]) +def test_open_session_passes_port_to_kernel_as_port_kwarg(monkeypatch, port): + """A set ``_port`` reaches the binding as ``port=`` as is. The host is passed + unchanged: the kernel validates the port and applies it, not the driver.""" + captured = {} + + def fake_session(**kw): + captured.update(kw) + return MagicMock(session_id="sess-id") + + monkeypatch.setattr(kernel_client._kernel, "Session", fake_session) + c = kernel_client.KernelDatabricksClient( + server_hostname="example.cloud.databricks.com", + http_path="/sql/1.0/warehouses/abc", + auth_provider=AccessTokenAuthProvider("dapi-test"), + ssl_options=None, + port=port, + ) + c.open_session(session_configuration=None, catalog=None, schema=None) + + assert captured["host"] == "example.cloud.databricks.com" + assert captured["port"] == port + + +def test_open_session_sends_no_port_kwarg_without_a_port(monkeypatch): + """An unset ``_port`` sends no ``port`` kwarg, so the default path is unchanged.""" + captured = {} + + def fake_session(**kw): + captured.update(kw) + return MagicMock(session_id="sess-id") + + monkeypatch.setattr(kernel_client._kernel, "Session", fake_session) + c = kernel_client.KernelDatabricksClient( + server_hostname="example.cloud.databricks.com", + http_path="/sql/1.0/warehouses/abc", + auth_provider=AccessTokenAuthProvider("dapi-test"), + ssl_options=None, + ) + c.open_session(session_configuration=None, catalog=None, schema=None) + + assert "port" not in captured + assert captured["host"] == "example.cloud.databricks.com" + + +def test_open_session_port_on_a_kernel_without_port_raises_not_supported( + monkeypatch, +): + def fake_session_without_port(host, http_path, *, enable_geospatial_support=False): + raise AssertionError("must not construct a session") + + monkeypatch.setattr(kernel_client._kernel, "Session", fake_session_without_port) + c = kernel_client.KernelDatabricksClient( + server_hostname="example.cloud.databricks.com", + http_path="/sql/1.0/warehouses/abc", + auth_provider=AccessTokenAuthProvider("dapi-test"), + ssl_options=None, + port=8443, + ) + + with pytest.raises(NotSupportedError, match="newer databricks-sql-kernel"): + c.open_session(session_configuration=None, catalog=None, schema=None) + + def test_open_session_passes_phase_7_telemetry_kwargs_to_kernel(monkeypatch): """Kernel telemetry phase 7 added binding/runtime identity and telemetry config kwargs to ``databricks_sql_kernel.Session``.""" diff --git a/tests/unit/test_session.py b/tests/unit/test_session.py index fb889d856..976c9a7c1 100644 --- a/tests/unit/test_session.py +++ b/tests/unit/test_session.py @@ -2,6 +2,11 @@ from unittest.mock import patch, MagicMock, Mock, PropertyMock from contextlib import contextmanager import gc +import importlib.metadata as ilm +import socket +import sys +import threading +import types from databricks.sql.thrift_api.TCLIService.ttypes import ( TOpenSessionResp, @@ -10,15 +15,17 @@ ) from databricks.sql.backend.types import SessionId, BackendType from databricks.sql.common.agent import KNOWN_AGENTS +from databricks.sql.session import _kernel_endpoint + +import databricks.sql from databricks.sql.exc import ( ReydenThriftUnsupportedError, DatabaseError, + NotSupportedError, OperationalError, ) from databricks.sql.session import Session -import databricks.sql - class TestSession: """ @@ -1184,3 +1191,358 @@ def test_pat_recovery_does_not_inject_auth_type(self, mock_thrift): assert kwargs["auth_options"].get("auth_type") is None finally: conn.close() + + +# ---- kernel _port / _connection_uri resolution (use_kernel=True) ---- +# The kernel applies _port (host:port folding, IPv6 brackets, embedded-port rules, and +# credential/path/query checks), so these tests cover only what the driver resolves: +# the host, the port and the path that reach the kernel. + +_P = "/sql/1.0/warehouses/abc" + + +@pytest.mark.parametrize( + "server, kwargs, expected_port", + [ + # _port and server_hostname reach the kernel as is; the kernel validates both. + ("h.io", {"_port": 8443}, 8443), + ("h.io", {"_port": 443}, 443), + ("h.io:8443", {"_port": "bad"}, "bad"), + ("h.io", {}, None), + ], +) +def test_kernel_endpoint_passes_host_unchanged_and_port_separately( + server, kwargs, expected_port +): + assert _kernel_endpoint(server, _P, kwargs) == (server, _P, expected_port) + + +@pytest.mark.parametrize( + "kwargs, expected", + [ + # _connection_uri gives the host (with any port), the path and the query. It wins + # over _port, which is not passed. + ( + {"_connection_uri": "https://d.io:8443/sql/1.0/warehouses/xyz"}, + ("https://d.io:8443", "/sql/1.0/warehouses/xyz", None), + ), + ( + {"_connection_uri": "https://h.io/sql/x?o=123"}, + ("https://h.io", "/sql/x?o=123", None), + ), + ( + {"_connection_uri": "http://h.io:8080/sql/x"}, + ("http://h.io:8080", "/sql/x", None), + ), + ( + {"_connection_uri": "https://d.io:9999/p", "_port": 8443}, + ("https://d.io:9999", "/p", None), + ), + ], +) +def test_connection_uri_resolves_host_and_path_and_passes_no_port(kwargs, expected): + assert _kernel_endpoint("h.io", _P, kwargs) == expected + + +def test_connection_uri_only_resolves_host_and_path(): + assert _kernel_endpoint("", "", {"_connection_uri": "https://h.io/sql/x"}) == ( + "https://h.io", + "/sql/x", + None, + ) + + +@pytest.mark.parametrize( + "kwargs, message", + [ + # _connection_uri must be http(s) with a host and no credentials; the kernel + # validates the rest. + ({"_connection_uri": "d.io/sql/x"}, "Invalid _connection_uri"), + ({"_connection_uri": "ftp://h.io/sql/x"}, "Invalid _connection_uri"), + ({"_connection_uri": "https://u:p@h.io/sql/x"}, "Invalid _connection_uri"), + ({"_connection_uri": "https:///sql/x"}, "Invalid _connection_uri"), + ], +) +def test_kernel_endpoint_rejects_driver_owned_inputs(kwargs, message): + with pytest.raises(ValueError, match=message): + _kernel_endpoint("h", _P, kwargs) + + +@pytest.mark.parametrize( + "server, port", + [ + ("h.io:8443", 443), + ("h.io", 8443), + ("h.io/x", 8443), + ("h.io", ""), + ], +) +@patch("databricks.sql.session.ThriftDatabricksClient") +def test_thrift_receives_host_and_port_unchanged(mock_client_class, server, port): + # Thrift is unchanged: the host and _port reach ThriftDatabricksClient verbatim, and + # ThriftDatabricksClient applies its own `port or 443` to the URL. The kernel-only + # port handling above does not apply here. + connection = databricks.sql.connect( + server_hostname=server, + http_path=_P, + access_token="tok", + enable_telemetry=False, + _port=port, + ) + call_kwargs = mock_client_class.call_args.kwargs + assert call_kwargs["server_hostname"] == server + assert call_kwargs["port"] == port + connection.close() + + +@pytest.mark.parametrize( + "conn_kwargs, expected_host, expected_path, expected_port", + [ + # _port reaches the kernel client as is; server_hostname is unchanged. + ( + {"server_hostname": "h.io", "http_path": _P, "_port": 8443}, + "h.io", + _P, + 8443, + ), + ({"server_hostname": "h.io", "http_path": _P, "_port": 443}, "h.io", _P, 443), + # A digit string (env var or DSN) becomes an int; any other value passes as is. + ( + {"server_hostname": "h.io", "http_path": _P, "_port": "8443"}, + "h.io", + _P, + 8443, + ), + ( + {"server_hostname": "h.io", "http_path": _P, "_port": " 443 "}, + "h.io", + _P, + 443, + ), + ( + {"server_hostname": "h.io", "http_path": _P, "_port": "abc"}, + "h.io", + _P, + "abc", + ), + # Unset sends no port. + ({"server_hostname": "h.io", "http_path": _P}, "h.io", _P, None), + # _connection_uri supplies the host (with its port) and the path; no port. + ( + { + "server_hostname": "h.io", + "http_path": _P, + "_connection_uri": f"https://d.io:9999{_P}", + "_port": 8443, + }, + "https://d.io:9999", + _P, + None, + ), + ( + { + "server_hostname": "", + "http_path": "", + "_connection_uri": f"https://d.io:9999{_P}", + }, + "https://d.io:9999", + _P, + None, + ), + ], +) +def test_resolved_kernel_host_and_path_reach_kernel_client( + fake_kernel, conn_kwargs, expected_host, expected_path, expected_port +): + client, _ = fake_kernel + databricks.sql.connect( + use_kernel=True, + access_token="dapi-xyz", + enable_telemetry=False, + **conn_kwargs, + ).close() + kwargs = client.call_args.kwargs + assert kwargs["server_hostname"] == expected_host + assert kwargs["http_path"] == expected_path + assert kwargs["port"] == expected_port + + +@pytest.fixture +def fake_kernel(): + """Fake the kernel wheel and client so connect() runs without a warehouse.""" + pytest.importorskip( + "pyarrow", reason="kernel client module imports pyarrow at load" + ) + fake = types.ModuleType("databricks_sql_kernel") + fake.KernelError = type("KernelError", (Exception,), {}) + fake.Session = MagicMock() + with patch.dict(sys.modules, {"databricks_sql_kernel": fake}), patch( + "databricks.sql.backend.kernel.client.KernelDatabricksClient" + ) as client, patch("databricks.sql.session.get_python_sql_connector_auth_provider"): + client.return_value.open_session.return_value = SessionId( + BackendType.SEA, "sess-id", None + ) + yield client, fake + + +@pytest.mark.parametrize( + "hp, uri, expected_org", + [ + ("/sql/1.0/warehouses/abc?o=111", "https://d.io/sql/x?o=222", "222"), + ("/sql/1.0/warehouses/abc?o=111", "https://d.io/sql/x", None), + ("/sql/1.0/warehouses/abc", "https://d.io/sql/x?o=222", "222"), + ("/sql/1.0/warehouses/abc?o=111", None, "111"), + ], +) +def test_spog_org_id_follows_resolved_path(fake_kernel, hp, uri, expected_org): + client, _ = fake_kernel + extra = {"_connection_uri": uri} if uri else {} + databricks.sql.connect( + server_hostname="h.io", + http_path=hp, + access_token="dapi", + use_kernel=True, + enable_telemetry=False, + **extra, + ).close() + assert ( + dict(client.call_args.kwargs["http_headers"]).get("x-databricks-org-id") + == expected_org + ) + + +def _require_real_kernel_wheel(port_kwarg): + """Skip unless the kernel wheel is installed and, when ``port_kwarg`` is set, its + ``Session`` takes ``port``. An older wheel raises NotSupportedError for a non-default + ``_port``, which a loopback test would otherwise report as a listener timeout.""" + try: + ilm.version("databricks-sql-kernel") + except ilm.PackageNotFoundError: + pytest.skip("databricks-sql-kernel wheel not installed") + if not getattr(__import__("databricks_sql_kernel"), "__file__", None): + pytest.fail( + "databricks-sql-kernel is installed but sys.modules holds a stub " + "(no __file__); a unit-test fake is shadowing the real wheel." + ) + if port_kwarg: + from databricks.sql.backend.kernel import client as kernel_client + + if not kernel_client._kernel_session_accepts_kwarg("port"): + pytest.skip("installed databricks-sql-kernel wheel has no port kwarg") + + +@pytest.mark.realkernel +@pytest.mark.parametrize( + "build, port_kwarg", + [ + ( + lambda p: {"server_hostname": "127.0.0.1", "http_path": _P, "_port": p}, + True, + ), + ( + lambda p: { + "server_hostname": "", + "http_path": "", + "_connection_uri": f"https://127.0.0.1:{p}{_P}", + }, + False, + ), + ], + ids=["port", "uri-only"], +) +def test_kernel_dials_over_tls(build, port_kwarg): + """Loopback dial on the real kernel wheel: a TCP listener on 127.0.0.1 must receive the + kernel's TLS handshake (first byte 0x16) at the requested port. Nothing completes the + handshake, so connect() is expected to fail; only the dial is asserted.""" + _require_real_kernel_wheel(port_kwarg) + listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + listener.bind(("127.0.0.1", 0)) + listener.listen(1) + listener.settimeout(60) + port = listener.getsockname()[1] + received = {} + + def accept_one(): + try: + sock, _ = listener.accept() + sock.settimeout(10) + received["first_byte"] = sock.recv(1) + sock.close() + except OSError as exc: + received["error"] = repr(exc) + finally: + listener.close() + + thread = threading.Thread(target=accept_one, daemon=True) + thread.start() + try: + databricks.sql.connect( + use_kernel=True, + access_token="dapi-xyz", + enable_telemetry=False, + _retry_stop_after_attempts_count=1, + **build(port), + ).close() + except NotSupportedError: + raise + except Exception: + pass # expected: nothing behind the listener completes TLS + thread.join(timeout=70) + assert "error" not in received, received + assert received.get("first_byte") == b"\x16", received + + +@pytest.mark.realkernel +def test_kernel_embedded_port_wins_over_explicit_port(): + """Loopback on the real kernel wheel: server_hostname 'h:P1' with an explicit _port P2 + dials P1 (TLS first byte 0x16) and never P2.""" + _require_real_kernel_wheel(port_kwarg=True) + + def listen(): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.bind(("127.0.0.1", 0)) + sock.listen(1) + sock.settimeout(15) + return sock + + embedded, explicit = listen(), listen() + embedded_port = embedded.getsockname()[1] + explicit_port = explicit.getsockname()[1] + received = {} + + def accept_one(name, sock): + try: + conn, _ = sock.accept() + conn.settimeout(10) + received[name] = conn.recv(1) + conn.close() + except OSError as exc: + received[name + "_error"] = repr(exc) + finally: + sock.close() + + threads = [ + threading.Thread(target=accept_one, args=("embedded", embedded), daemon=True), + threading.Thread(target=accept_one, args=("explicit", explicit), daemon=True), + ] + for thread in threads: + thread.start() + try: + databricks.sql.connect( + server_hostname=f"127.0.0.1:{embedded_port}", + http_path=_P, + use_kernel=True, + access_token="dapi-xyz", + enable_telemetry=False, + _retry_stop_after_attempts_count=1, + _port=explicit_port, + ).close() + except NotSupportedError: + raise + except Exception: + pass # expected: nothing behind the listener completes TLS + for thread in threads: + thread.join(timeout=70) + assert received.get("embedded") == b"\x16", received + assert "explicit" not in received, received + assert "explicit_error" in received, received