Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PYTHON-4440 - Add executor thread limit for pyopenssl_context #1690

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pymongo/pyopenssl_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import ssl as _stdlibssl
import sys as _sys
import time as _time
from concurrent.futures import ThreadPoolExecutor
from errno import EINTR as _EINTR
from ipaddress import ip_address as _ip_address
from typing import TYPE_CHECKING, Any, Callable, Optional, TypeVar, Union
Expand Down Expand Up @@ -97,6 +98,10 @@ def _ragged_eof(exc: BaseException) -> bool:
return exc.args == (-1, "Unexpected EOF")


# TODO: Make max_workers = MAX_CONNECTING
_executor = ThreadPoolExecutor(max_workers=2)


# https://github.com/pyca/pyopenssl/issues/168
# https://github.com/pyca/pyopenssl/issues/176
# https://docs.python.org/3/library/ssl.html#notes-on-non-blocking-sockets
Expand Down Expand Up @@ -391,15 +396,15 @@ async def a_wrap_socket(
ssl_conn.set_tlsext_host_name(server_hostname.encode("idna"))
if self.verify_mode != _stdlibssl.CERT_NONE:
# Request a stapled OCSP response.
await loop.run_in_executor(None, ssl_conn.request_ocsp)
await loop.run_in_executor(_executor, ssl_conn.request_ocsp)
ssl_conn.set_connect_state()
# If this wasn't true the caller of wrap_socket would call
# do_handshake()
if do_handshake_on_connect:
# XXX: If we do hostname checking in a callback we can get rid
# of this call to do_handshake() since the handshake
# will happen automatically later.
await loop.run_in_executor(None, ssl_conn.do_handshake)
await loop.run_in_executor(_executor, ssl_conn.do_handshake)
# XXX: Do this in a callback registered with
# SSLContext.set_info_callback? See Twisted for an example.
if self.check_hostname and server_hostname is not None:
Expand Down
Loading