-
-
Notifications
You must be signed in to change notification settings - Fork 99
move ssl_handshake handling from main thread to worker threads #750
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
base: main
Are you sure you want to change the base?
move ssl_handshake handling from main thread to worker threads #750
Conversation
β 21 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR shifts SSL handshake processing from the main thread to worker threads by introducing an explicit get()
method in the thread pool and adding a do_handshake
API to the built-in SSL adapter.
- Removed the
self.get = ...
alias and implementedThreadPool.get()
to perform the SSL handshake if needed. - Updated the built-in SSL adapter to defer handshake on wrap and provide a
do_handshake
method with error handling and plaintext fallback. - Synchronized type stubs (
.pyi
) with the newget
anddo_handshake
signatures.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
cheroot/workers/threadpool.pyi | Removed old get attribute and added a typed def get() . |
cheroot/workers/threadpool.py | Added get() logic to invoke SSL handshake; removed alias. |
cheroot/ssl/builtin.pyi | Added do_handshake(conn) -> None stub. |
cheroot/ssl/builtin.py | Switched off auto handshake in wrap() and implemented do_handshake with helpers. |
Comments suppressed due to low confidence (1)
cheroot/ssl/builtin.py:323
- New SSL handshake logic, including plaintext fallback and error branches, should be covered by unit or integration tests to ensure correct behavior under success, SSL errors, and plain-HTTP-over-HTTPS scenarios.
def do_handshake(self, conn):
""" | ||
conn = self._queue.get() | ||
ssl_adapter = self.server.ssl_adapter |
Copilot
AI
Jun 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accessing self.server.ssl_adapter
directly can raise an AttributeError
if the server has no ssl_adapter
. Consider using getattr(self.server, 'ssl_adapter', None)
to guard against missing attributes.
ssl_adapter = self.server.ssl_adapter | |
ssl_adapter = getattr(self.server, 'ssl_adapter', None) |
Copilot uses AI. Check for mistakes.
try: | ||
conn.socket.shutdown(socket.SHUT_RDWR) | ||
except Exception: | ||
# pass |
Copilot
AI
Jun 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commented-out # pass
line can be removed to clean up the code and avoid confusion about whether this exception block is intentional.
# pass |
Copilot uses AI. Check for mistakes.
Args: | ||
conn (:py:class:`~cheroot.server.HTTPConnection`): HTTP connection | ||
""" | ||
ssl_handshake_must_be_done = ( |
Copilot
AI
Jun 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This do_handshake
method is long and handles multiple concerns. Consider refactoring into smaller private helpers (e.g., handle_plain_http
, log_handshake_error
) for readability and easier maintenance.
Copilot uses AI. Check for mistakes.
@bmourgues I requested co-pilot to review, but don't take its comments too seriously (unless you double-check its suggestions by yourself): it's not good at understanding context. I haven't yet had time to make a proper review myself. |
β What kind of change does this PR introduce?
π What is the related issue number (starting with
#
)Resolves #748
Resolves #709
β What is the current behavior? (You can also link to an open issue here)
β What is the new behavior (if this is a feature change)?
π Other information:
π Contribution checklist:
(If you're a first-timer, check out
this guide on making great pull requests)
the changes have been approved
and description in grammatically correct, complete sentences
This change isβ