Skip to content

Commit 4888fa8

Browse files
rodrigobnogueirarodrigo.nogueira
authored andcommitted
Merge branch 'master' into dynamic-ports-finish
2 parents 7553ebe + 2d03bc4 commit 4888fa8

4 files changed

Lines changed: 19 additions & 18 deletions

File tree

CHANGES/12170.misc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed race condition in ``test_data_file`` on Python 3.14 free-threaded builds -- by :user:`rodrigobnogueira`.

aiohttp/formdata.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
from collections import deque
23
from collections.abc import Iterable
34
from typing import Any
45
from urllib.parse import urlencode
@@ -81,10 +82,10 @@ def add_field(
8182
self._fields.append((type_options, headers, value))
8283

8384
def add_fields(self, *fields: Any) -> None:
84-
to_add = list(fields)
85+
to_add: deque[Any] = deque(fields)
8586

8687
while to_add:
87-
rec = to_add.pop(0)
88+
rec = to_add.popleft()
8889

8990
if isinstance(rec, io.IOBase):
9091
k = guess_filename(rec, "unknown")

docs/web_reference.rst

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,7 +2902,9 @@ application on specific TCP or Unix socket, e.g.::
29022902

29032903
:param str host: HOST to listen on, all interfaces if ``None`` (default).
29042904

2905-
:param int port: PORT to listed on, ``8080`` if ``None`` (default).
2905+
:param int port: PORT to listen on, ``8080`` if ``None`` (default).
2906+
Use ``0`` to let the OS assign a free ephemeral port
2907+
(see :attr:`port`).
29062908

29072909
:param float shutdown_timeout: a timeout used for both waiting on pending
29082910
tasks before application shutdown and for
@@ -2935,20 +2937,6 @@ application on specific TCP or Unix socket, e.g.::
29352937
Read-only. The actual port number the server is bound to, only
29362938
guaranteed to be correct after the site has been started.
29372939

2938-
To bind to a dynamic port, pass ``0`` as the port number. The OS
2939-
will assign a free port which can then be retrieved from this
2940-
attribute::
2941-
2942-
app = web.Application()
2943-
runner = web.AppRunner(app)
2944-
await runner.setup()
2945-
site = web.TCPSite(runner, 'localhost', 0)
2946-
await site.start()
2947-
2948-
print(f"Server started on port {site.port}")
2949-
while True:
2950-
await asyncio.sleep(3600) # sleep forever
2951-
29522940

29532941
.. class:: UnixSite(runner, path, *, \
29542942
shutdown_timeout=60.0, ssl_context=None, \

tests/test_client_request.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,18 @@ async def test_data_file(
13521352
assert isinstance(req.body, payload.BufferedReaderPayload)
13531353
assert req.headers["TRANSFER-ENCODING"] == "chunked"
13541354

1355-
resp = await req._send(conn)
1355+
original_write_bytes = req._write_bytes
1356+
1357+
async def _mock_write_bytes(
1358+
writer: AbstractStreamWriter, conn: mock.Mock, content_length: int | None
1359+
) -> None:
1360+
# Ensure the task is scheduled so _writer isn't None
1361+
await asyncio.sleep(0)
1362+
await original_write_bytes(writer, conn, content_length)
1363+
1364+
with mock.patch.object(req, "_write_bytes", _mock_write_bytes):
1365+
resp = await req._send(conn)
1366+
13561367
assert asyncio.isfuture(req._writer)
13571368
await resp.wait_for_close()
13581369

0 commit comments

Comments
 (0)