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

Make pytest pass locally with Python 3.12 #40

Merged
merged 4 commits into from
Jul 11, 2024
Merged

Make pytest pass locally with Python 3.12 #40

merged 4 commits into from
Jul 11, 2024

Conversation

mkmkme
Copy link
Collaborator

@mkmkme mkmkme commented Jul 10, 2024

Pull Request check-list

Please make sure to review and check all of these items:

  • Do tests and lints pass with this change?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Description of change

This is the first PR addressed to fix #24. It contains a smaller amount of changes, but each change is complicated enough to move this bunch into a separate PR.

There will be a second one, fixing calls for invoke and some style issues.

These commits fix missing dependencies and deadlocks.

tests/test_connect.py Dismissed Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 68.18182% with 7 lines in your changes missing coverage. Please review.

Project coverage is 75.01%. Comparing base (f1898b9) to head (e001c88).

Files Patch % Lines
valkey/commands/graph/query_result.py 12.50% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
- Coverage   75.02%   75.01%   -0.01%     
==========================================
  Files         132      132              
  Lines       34352    34368      +16     
==========================================
+ Hits        25771    25781      +10     
- Misses       8581     8587       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aiven-sal aiven-sal self-requested a review July 11, 2024 12:59
mkmkme added 4 commits July 11, 2024 17:54
Python 3.12 removes `distutils` module completely, as advised
in PEP 632. Migration notes [1] advises to reimplement `strtobool` as
there is no module that replaces it.

The implementation of the function is straighforward since the whole
logic is described in `distutils` API reference [2].

This commit reimplements this function to drop `distutils` dependency
completely.

[1]: https://peps.python.org/pep-0632/#migration-advice
[2]: https://docs.python.org/3.9/distutils/apiref.html#distutils.util.strtobool

Signed-off-by: Mikhail Koviazin <[email protected]>
`ssl.wrap_socket` was removed in favour of using
`SSLContext.wrap_socket`. Creating an SSL context in this scenario is
straightforward, as it only needs cert and key files.

Signed-off-by: Mikhail Koviazin <[email protected]>
There was a breaking change in `wait_closed()` in Python 3.12 that
caused some tests from test_connect to hang indefinitely. The reason for
that was the fact that `wait_closed()` was waiting for all handlers to
finish their execution, while the handler expected `stop_event` to be
set. `stop_event` was set only *after* `wait_closed()` would have
finished and returned the control, which caused a deadlock.

This commit fixes the deadlock by setting `stop_event` right before
calling for `conn.disconnect()`. This makes sense, because at that
moment handling more new requests is not needed as connection is going
to be closed.
The old call for `stop_event.set()` is kept for the unlikely case when
there was a connection error and the execution did not reach
`stop_event.set()` call in `try` block. If it was reached, this call
will be a noop.

[1]: python/cpython#104344

Signed-off-by: Mikhail Koviazin <[email protected]>
`NodeProxy` acts as a proxy server that connects to Valkey. In its
handler, it creates two pipes:
	1. Connecting valkey reader to own writer
	2. Connecting own reader to valkey writer

Then, it `await`s on these two pipes via `asyncio.gather`.
`asyncio.gather` itself returns a future that can be canceled, and
originally it was assumingly thought that canceling `self.task` in
`NodeProxy` would cancel the pipes, too. That was not the case. This
behaviour caused warnings in Python 3.9. On Python 3.12, it caused a
deadlock.

In order to fix it, the pipes future should be assigned to a variable so
that it can be canceled explicitly upon `aclose()`. Additionally, the
`NodeProxy`'s handler should handle a situation when pipes future was
canceled and close the `Writer` side in order for the loop to end
gracefully.

This commit introduces `self.pipes` in `NodeProxy` and handles the
cancellation properly therefore fixing the deadlock.

Signed-off-by: Mikhail Koviazin <[email protected]>
@aiven-sal aiven-sal merged commit 9c5e2b7 into valkey-io:main Jul 11, 2024
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add development support for python 3.12
3 participants