Commit graph

972 commits

Author SHA1 Message Date
Miss Islington (bot)
ccc6c2b8c0
[3.12] gh-120226: Fix test_sendfile_close_peer_in_the_middle_of_receiving on Linux >= 6.10 (GH-120227) (#123422)
gh-120226: Fix test_sendfile_close_peer_in_the_middle_of_receiving on Linux >= 6.10 (GH-120227)

The worst case is that the kernel buffers 17 pages with a page size of 64k.
(cherry picked from commit a758424566)

Co-authored-by: Xi Ruoyao <xry111@xry111.site>
2024-08-28 12:47:41 +00:00
Miss Islington (bot)
41090b7ba0
[3.12] gh-112182: Replace StopIteration with RuntimeError for future (GH-113220) (GH-123033)
When an `StopIteration` raises into `asyncio.Future`, this will cause
a thread to hang. This commit address this by not raising an exception
and silently transforming the `StopIteration` with a `RuntimeError`,
which the caller can reconstruct from `fut.exception().__cause__`
(cherry picked from commit 4826d52338)

Co-authored-by: Jamie Phan <jamie@ordinarylab.dev>
2024-08-15 15:34:53 +00:00
Victor Stinner
c57a33d006
[3.12] gh-122695: Fix double-free when using gc.get_referents with a freed _asyncio.FutureIter (#122837) (#122859)
[3.13] gh-122695: Fix double-free when using `gc.get_referents` with a freed `_asyncio.FutureIter` (#122837)

* Backport #122834 for 3.13

(cherry picked from commit e8fb088dba)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-08-09 14:33:24 +00:00
Miss Islington (bot)
102dc44a0a
[3.12] gh-122332: Fix missing NULL check in asyncio.Task.get_coro (GH-122338) (#122345)
gh-122332: Fix missing `NULL` check in `asyncio.Task.get_coro` (GH-122338)
(cherry picked from commit c08696286f)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2024-07-27 12:36:40 +05:30
Miss Islington (bot)
41e1ac6a23
[3.12] gh-121025: Improve partialmethod.__repr__ (GH-121033) (GH-121038)
It no longer contains redundant commas and spaces.
(cherry picked from commit d2646e3f45)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2024-06-26 09:29:59 +00:00
Miss Islington (bot)
55f65156cb
[3.12] gh-113892: Add a extra check to ProactorEventLoop.sock_connect to ensure that the given socket is in non-blocking mode (GH-119519) (#119913)
(cherry picked from commit cf3bba3f06)

Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-06-01 16:29:34 +00:00
Serhiy Storchaka
33a9f0ce65
[3.12] gh-119064: Use os_helper.FakePath instead of pathlib.Path in tests (GH-119065) (GH-119088)
(cherry picked from commit 0152dc4ff5)
2024-05-16 08:04:37 +00:00
Miss Islington (bot)
bd2c60f8c2
[3.12] gh-91227: Ignore ERROR_PORT_UNREACHABLE in proactor recvfrom() (GH-32011) (GH-117209)
(cherry picked from commit f11d0d8be8)

Co-authored-by: Erik Soma <stillusingirc@gmail.com>
2024-03-25 12:21:31 +02:00
Miss Islington (bot)
05c5bece78
[3.12] gh-116333: Relax error string text expectations in SSL-related tests (GH-116334) (GH-117136)
gh-116333: Relax error string text expectations in SSL-related tests (GH-116334)

* Relax error string text expectations in SSL-related tests

As suggested [here][1], this change relaxes the OpenSSL error string
text expectations in a number of tests. This was specifically done in
support of more easily building CPython [AWS-LC][2], but because AWS-LC
is a fork of [BoringSSL][3], it should increase compatibility with that
library as well.

In addition to the error string relaxations, we also add some guards
around the `tls-unique` channel binding being used with TLSv1.3, as that
feature (described in [RFC 6929][4]) is [not defined][5] for TLSv1.3.

[1]: https://discuss.python.org/t/support-building-ssl-and-hashlib-modules-against-aws-lc/44505/4
[2]: https://github.com/aws/aws-lc
[3]: https://github.com/google/boringssl
[4]: https://datatracker.ietf.org/doc/html/rfc5929GH-section-3
[5]: https://datatracker.ietf.org/doc/html/rfc8446GH-appendix-C.5
(cherry picked from commit c85d84166a)

Co-authored-by: Will Childs-Klein <willck93@gmail.com>
2024-03-21 20:46:20 +00:00
jkriegshauser
d69c51520e
[3.12] gh-116773: Fix overlapped memory corruption crash (GH-116774) (#117078)
Manual backport of gh-116774.
2024-03-20 13:10:15 -07:00
Terry Jan Reedy
84b023d243
[3.12] chore: fix typos (#116345) (#116370)
Co-authored-by: cui fliter <imcusg@gmail.com>
(cherry picked from commit e7ba6e9dbe)
2024-03-05 18:51:17 +00:00
Miss Islington (bot)
e25ac3ba1d
[3.12] gh-111358: Fix timeout behaviour in BaseEventLoop.shutdown_default_executor (GH-115622) (#115641)
(cherry picked from commit 53d5e67804)

Co-authored-by: Jamie Phan <jamie@ordinarylab.dev>
2024-02-19 00:17:40 +00:00
Travis Howse
49fbb068d5
[3.12] gh-114887 Reject only sockets of type SOCK_STREAM in create_da… (#114980)
Also improve exception message.

(cherry picked from commit 94ec2b9c9c)

Co-authored-by: Donghee Na <donghee.na92@gmail.com>
2024-02-04 15:42:06 -08:00
Miss Islington (bot)
41a94c9e7b
[3.12] gh-109862: Fix test_create_subprocess_with_pidfd when it was run separately (GH-113991) (GH-114072)
(cherry picked from commit f8a79109d0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-01-15 07:55:35 +00:00
Alois Klink
fa7d8e97c2
[3.12] gh-95649: Document that asyncio contains uvloop code (GH-107536) (#114046)
Some of the asyncio SSL changes in GH-31275 [1] were taken from
v0.16.0 of the uvloop project [2]. In order to comply with the MIT
license, we need to just need to document the copyright information.

[1]: https://github.com/python/cpython/pull/31275
[2]: https://github.com/MagicStack/uvloop/tree/v0.16.0

(cherry picked from commit dce30c9cbc)
2024-01-14 02:15:06 +00:00
Miss Islington (bot)
92ba4e10fa
[3.12] gh-113538: Don't error in stream reader protocol callback when task is cancelled (GH-113690) (#113713)
(cherry picked from commit 4681a5271a)

Co-authored-by: Guido van Rossum <guido@python.org>
2024-01-04 20:51:53 +00:00
Miss Islington (bot)
7f2ebc84e8
[3.12] gh-112559: Avoid unnecessary conversion attempts to enum_klass in signal.py (GH-113040) (#113443)
(cherry picked from commit 050783cb37)

Co-authored-by: Yilei Yang <yileiyang@google.com>
2023-12-23 18:09:59 -08:00
Miss Islington (bot)
192711856b
[3.12] GH-113214: Fix SSLProto exception handling in SSL-over-SSL scenarios (GH-113334) (#113339)
When wrapped, `_SSLProtocolTransport._force_close(exc)` is called just like in the unwrapped scenario `_SelectorTransport._force_close(exc)` or `_ProactorBasePipeTransport._force_close(exc)` would be called, except here the exception needs to be passed through the `SSLProtocol._abort()` method, which didn't accept an exception object.

This commit ensures that this path works, in the same way that the uvloop implementation of SSLProto passes on the exception (on which the current implementation of SSLProto is based).

(cherry picked from commit 1ff0238594)

Co-authored-by: Martijn Pieters <mj@zopatista.com>
2023-12-20 16:51:36 -08:00
Miss Islington (bot)
f521321ddf
[3.12] gh-112186: Improve test case test_loop_is_closed_resource_warnings (GH-112187) (#112255)
(cherry picked from commit 18c6929469)

Co-authored-by: DPR <dpr-0xff@pm.me>
2023-11-19 07:19:12 -08:00
DPR
2ef3676a5b
[3.12] gh-109538: Catch closed loop runtime error and issue warning (GH-111983) (#112142)
* [3.12] gh-109538: Avoid RuntimeError when StreamWriter is deleted with closed loop (GH-111983)

Issue a ResourceWarning instead.

(cherry picked from commit e0f5127975)
gh-109538: Avoid RuntimeError when StreamWriter is deleted with closed loop (#111983)

Issue a ResourceWarning instead.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
(cherry picked from commit e0f5127975)

* Fix missing warnings import
2023-11-16 09:40:55 -08:00
Miss Islington (bot)
d15fac2a67
[3.12] gh-111644: Fix asyncio test_unhandled_exceptions() (GH-111713) (#111718)
gh-111644: Fix asyncio test_unhandled_exceptions() (GH-111713)

Fix test_unhandled_exceptions() of test_asyncio.test_streams: break
explicitly a reference cycle.

Fix also StreamTests.tearDown(): the loop must not be closed
explicitly, but using set_event_loop() which takes care of shutting
down the executor with executor.shutdown(wait=True).
BaseEventLoop.close() calls executor.shutdown(wait=False).
(cherry picked from commit ac01e2243a)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-11-04 06:29:20 +00:00
Kumar Aditya
9aa88290d8
[3.12] GH-110894: Call loop exception handler for exceptions in client_connected_cb (GH-111601) (#111632)
Call loop exception handler for exceptions in `client_connected_cb` of `asyncio.start_server` so that applications can handle it..
(cherry picked from commit 229f44d353)
2023-11-02 08:18:49 +00:00
Miss Islington (bot)
0681b4c82c
[3.12] gh-111347: Remove wrong assertion in test_sendfile (GH-111377) (#111461)
gh-111347: Remove wrong assertion in test_sendfile (GH-111377)

Windows is different.
(cherry picked from commit fa35b9e89b)

Co-authored-by: zcxsythenew <30565051+zcxsythenew@users.noreply.github.com>
2023-10-29 10:29:29 -07:00
Miss Islington (bot)
2e5d4e24eb
[3.12] gh-79033: Try to fix asyncio.Server.wait_closed() again (GH-111336) (#111424)
gh-79033: Try to fix asyncio.Server.wait_closed() again (GH-111336)

* Try to fix asyncio.Server.wait_closed() again

I identified the condition that `wait_closed()` is intended
to wait for: the server is closed *and* there are no more
active connections.

When this condition first becomes true, `_wakeup()` is called
(either from `close()` or from `_detach()`) and it sets `_waiters`
to `None`. So we just check for `self._waiters is None`; if it's
not `None`, we know we have to wait, and do so.

A problem was that the new test introduced in 3.12 explicitly
tested that `wait_closed()` returns immediately when the server
is *not* closed but there are currently no active connections.
This was a mistake (probably a misunderstanding of the intended
semantics). I've fixed the test, and added a separate test that
checks exactly for this scenario.

I also fixed an oddity where in `_wakeup()` the result of the
waiter was set to the waiter itself. This result is not used
anywhere and I changed this to `None`, to avoid a GC cycle.

* Update Lib/asyncio/base_events.py

---------

(cherry picked from commit 2655369559)

Co-authored-by: Guido van Rossum <guido@python.org>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2023-10-28 18:42:53 +00:00
Miss Islington (bot)
2398036eea
[3.12] gh-110205: Fix asyncio ThreadedChildWatcher._join_threads() (GH-110884) (#111412)
- `ThreadedChildWatcher.close()` is now *officially* a no-op; `_join_threads()` never did anything.
- Threads created by that class are now named `asyncio-waitpid-NNN`.
- `test.test_asyncio.utils.TestCase.close_loop()` now waits for the child watcher's threads, but not forever; if a thread hangs, it raises `RuntimeError`.
(cherry picked from commit c3bb10c930)

Co-authored-by: Guido van Rossum <guido@python.org>
2023-10-27 16:36:05 -07:00
Miss Islington (bot)
028f47754c
[3.12] gh-111085: Fix invalid state handling in TaskGroup and Timeout (GH-111111) (GH-111171)
asyncio.TaskGroup and asyncio.Timeout classes now raise proper RuntimeError
if they are improperly used.

* When they are used without entering the context manager.
* When they are used after finishing.
* When the context manager is entered more than once (simultaneously or
  sequentially).
* If there is no current task when entering the context manager.

They now remain in a consistent state after an exception is thrown,
so subsequent operations can be performed correctly (if they are allowed).

(cherry picked from commit 6c23635f2b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-10-21 19:48:53 +00:00
Miss Islington (bot)
9aa899354a
[3.12] gh-110695: test_asyncio uses 50 ms for clock resolution (GH-110952) (#110970)
gh-110695: test_asyncio uses 50 ms for clock resolution (GH-110952)

Before utils.CLOCK_RES constant was added (20 ms), test_asyncio
already used 50 ms.
(cherry picked from commit 9a9fba825f)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-17 10:13:31 +00:00
Miss Islington (bot)
c2d542b42c
[3.12] gh-108303: Move all certificates to Lib/test/certdata/ (GH-109489) (#109682)
* gh-108303: Move all certificates to `Lib/test/certdata/` (GH-109489)
(cherry picked from commit e57ecf6bbc)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

Python 3.12 backport: update also `test_nntplib`.

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Co-authored-by: T. Wouters <thomas@python.org>
2023-10-10 22:38:18 +02:00
Victor Stinner
e188534607
[3.12] Add support.MS_WINDOWS constant (#110446) (#110452)
Add support.MS_WINDOWS constant (#110446)

(cherry picked from commit e0c4437793)
2023-10-06 01:26:14 +00:00
Miss Islington (bot)
1d87465005
[3.12] gh-110335: asyncio test_unix_events cleans multiprocessing (GH-110336) (#110338)
gh-110335: asyncio test_unix_events cleans multiprocessing (GH-110336)

test_unix_events tests using the multiprocessing module now call
multiprocessing.util._cleanup_tests().
(cherry picked from commit 1337765225)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-04 12:33:14 +02:00
Victor Stinner
0745ab88e5
[3.12] gh-110088, gh-109878: Fix test_asyncio timeouts (#110092) (#110098)
gh-110088, gh-109878: Fix test_asyncio timeouts (#110092)

Fix test_asyncio timeouts: don't measure the maximum duration, a test
should not measure a CI performance. Only measure the minimum
duration when a task has a timeout or delay. Add CLOCK_RES to
test_asyncio.utils.

(cherry picked from commit db0a258e79)
2023-10-02 19:35:29 +00:00
Miss Islington (bot)
ce332aa8c5
[3.12] gh-110088: Fix asyncio test_prompt_cancellation() (GH-110157) (#110158)
gh-110088: Fix asyncio test_prompt_cancellation() (GH-110157)

Don't measure the CI performance: don't test the maximum elapsed
time. The check failed on a slow CI.
(cherry picked from commit c62b49ecc8)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-02 17:47:41 +02:00
Miss Islington (bot)
150bd302bb
[3.12] gh-109833: Fix asyncio test_wait_for() (GH-109834) (#109837)
gh-109833: Fix asyncio test_wait_for() (GH-109834)

Expect the test to be "short" but don't measure the exact performance
of the CI. SHORT_TIMEOUT is about 30 seconds whereas the cancelled
coroutine takes around 1 hour.
(cherry picked from commit f29bc9c9a0)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-02 17:24:51 +02:00
Miss Islington (bot)
c7cbd82e62
[3.12] gh-109709: Fix asyncio test_stdin_broken_pipe() (GH-109710) (#109731)
gh-109709: Fix asyncio test_stdin_broken_pipe() (GH-109710)

Replace harcoded sleep of 500 ms with synchronization using a pipe.

Fix also Process._feed_stdin(): catch also BrokenPipeError on
stdin.write(input), not only on stdin.drain().
(cherry picked from commit cbbdf2c144)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-02 17:21:51 +02:00
Miss Islington (bot)
05b139b599
[3.12] gh-109582: test_fork_signal_handling should wait for event (GH-109605) (#109695)
gh-109582: test_fork_signal_handling should wait for event (GH-109605)

Sometimes the child_handled event was missing because either
the child quits before it gets a chance to handle the signal,
or the parent asserts before the event notification is
delivered via IPC.  Synchronize explicitly to avoid this.
(cherry picked from commit 608c1f3083)

Co-authored-by: Davide Rizzo <sorcio@gmail.com>
2023-10-02 17:14:30 +02:00
Miss Islington (bot)
5ba9d2b98f
[3.12] gh-108973: Fix asyncio test_subprocess_consistent_callbacks() (GH-109431) (#109609)
gh-108973: Fix asyncio test_subprocess_consistent_callbacks() (GH-109431)

SubprocessProtocol process_exited() method can be called before
pipe_data_received() and pipe_connection_lost() methods. Document it
and adapt the test for that.

Revert commit 282edd7b2a.
_child_watcher_callback() calls immediately _process_exited(): don't
add an additional delay with call_soon(). The reverted change didn't
make _process_exited() more determistic: it can still be called
before pipe_connection_lost() for example.

(cherry picked from commit ced6924630)

Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Davide Rizzo <sorcio@gmail.com>
2023-10-02 17:03:51 +02:00
Miss Islington (bot)
8acfb42ea3
[3.12] gh-109295: Clean up multiprocessing in test_asyncio and test_compileall (GH-109298) (#109301)
gh-109295: Clean up multiprocessing in test_asyncio and test_compileall (GH-109298)

test_asyncio and test_compileall now clean up multiprocessing by
calling multiprocessing _cleanup_tests(): explicitly clean up
resources and stop background processes like the resource tracker.
(cherry picked from commit 09ea4b8706)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-09-12 16:22:43 +02:00
Miss Islington (bot)
c9dc2bc0de
[3.12] gh-109015: Add test.support.socket_helper.tcp_blackhole() (GH-109016) (#109041)
gh-109015: Add test.support.socket_helper.tcp_blackhole() (GH-109016)

Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).
(cherry picked from commit a52a350977)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-09-08 15:12:29 +02:00
Miss Islington (bot)
639ffd5aa0
[3.12] gh-107895: Fix test_asyncio.test_runners when run it in CPython's "development mode" (GH-108168) (#108196)
gh-107895: Fix test_asyncio.test_runners when run it in CPython's "development mode" (GH-108168)
(cherry picked from commit 014a5b71e7)

Co-authored-by: Joon Hwan 김준환 <xncbf12@gmail.com>
2023-08-21 13:18:04 +02:00
Kumar Aditya
9e6f8d4615
[3.12] gh-105987: Fix reference counting issue in `_asyncio._swap_cur… (#106099)
[3.12] gh-105987: Fix reference counting issue in `_asyncio._swap_current_task` (GH-105989).
(cherry picked from commit d2cbb6e918)

Co-authored-by: chgnrdv <52372310+chgnrdv@users.noreply.github.com>
2023-06-26 08:51:28 +00:00
Itamar Ostricher
a474e04388
gh-97696: asyncio eager tasks factory (#102853)
Co-authored-by: Jacob Bower <jbower@meta.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
2023-05-01 15:10:13 -06:00
Itamar Ostricher
85c7bf5bce
gh-103793: Defer formatting task name (#103767)
The default task name is "Task-<counter>" (if no name is passed in during Task creation).
This is initialized in `Task.__init__` (C impl) using string formatting, which can be quite slow.
Actually using the task name in real world code is not very common, so this is wasted init.

Let's defer this string formatting to the first time the name is read (in `get_name` impl),
so we don't need to pay the string formatting cost if the task name is never read.

We don't change the order in which tasks are assigned numbers (if they are) --
the number is set on task creation, as a PyLong instead of a formatted string.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2023-04-29 08:20:09 -07:00
Marek Marczykowski-Górecki
67d140dba7
gh-83925: Make asyncio.subprocess communicate similar to non-asyncio (#18650)
subprocess's communicate(None) closes stdin of the child process, after
sending no (extra) data. Make asyncio variant do the same.
This fixes issues with processes that waits for EOF on stdin before
continuing.
2023-04-27 17:30:26 -07:00
Itayazolay
78942ecd9b
gh-103607: Fix pause_reading to work when called from connection_made in asyncio. (#17425)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
2023-04-27 15:33:29 +05:30
Itamar Ostricher
518050ced1
gh-103780: Use patch instead of mock in asyncio unix events test (#103782) 2023-04-24 20:12:48 +00:00
Ali-Akber Saifee
19d2639d1e
gh-103462: Ensure SelectorSocketTransport.writelines registers a writer when data is still pending (#103463) 2023-04-13 10:16:52 +05:30
Irit Katriel
482b6eeadc
gh-102799: use sys.exception() instead of sys.exc_info() in tests (#103293) 2023-04-06 11:08:25 +01:00
Kristján Valur Jónsson
04adf2df39
gh-102780: Fix uncancel() call in asyncio timeouts (#102815)
Also use `raise TimeOut from <CancelledError instance>` so that the CancelledError is set
in the `__cause__` field rather than in the `__context__` field.

Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2023-03-22 10:52:10 -07:00
Irit Katriel
b3cc11a08e
gh-102799: remove unnecessary calls to sys.exc_info() in tests (#102800) 2023-03-18 07:19:38 +00:00
Kumar Aditya
4f5774f648
GH-78530: add support for generators in asyncio.wait (#102761) 2023-03-17 06:58:43 +05:30