aio-libs
aiohttp
BlogDocsChangelog

Fix race in `FileResponse` if file is replaced during `prepare`

#10101Merged
Comparing
race_wrong_stat
(
695e78c
) with
master
(
7557b03
)
CodSpeed Performance Gauge
+16%
Improvements
2
Untouched
43
Ignored
1

Benchmarks

Improved

test_simple_web_file_response[pyloop]
tests/test_benchmarks_web_fileresponse.py
CodSpeed Performance Gauge
+16%
95.5 ms82.3 ms
test_simple_web_file_sendfile_fallback_response[pyloop]
tests/test_benchmarks_web_fileresponse.py
CodSpeed Performance Gauge
+13%
100.7 ms88.8 ms

Passed

test_simple_web_response
tests/test_benchmarks_web_response.py
CodSpeed Performance Gauge
+2%
452.4 µs445.1 µs
test_resolve_root_route_with_many_fixed_routes[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
+1%
939.7 µs926.5 µs
test_resolve_multiple_level_fixed_url_with_many_routes[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
+1%
9.1 ms9 ms
test_resolve_single_fixed_url_with_many_routes[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
+1%
942 µs931.1 µs
test_web_response_with_headers
tests/test_benchmarks_web_response.py
CodSpeed Performance Gauge
+1%
887.4 µs877.8 µs
test_web_response_with_bytes_body
tests/test_benchmarks_web_response.py
CodSpeed Performance Gauge
+1%
542.6 µs537 µs
test_resolve_dynamic_resource_url_with_many_dynamic_routes_with_common_prefix[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
+1%
261.9 ms259.5 ms
test_create_client_request_with_cookies[pyloop]
tests/test_benchmarks_client_request.py
CodSpeed Performance Gauge
+1%
130.5 µs129.3 µs
test_resolve_gitapi[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
+1%
317.8 ms315.2 ms
test_resolve_root_route[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
+1%
936.9 µs930.2 µs
test_resolve_multiple_fixed_url_with_many_routes[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
+1%
2.3 ms2.3 ms
test_resolve_prefix_resources_many_prefix_many_plain[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
+1%
4.9 ms4.9 ms
test_resolve_dynamic_resource_url_with_many_static_routes[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
+1%
3.7 ms3.7 ms
test_serialize_headers
tests/test_benchmarks_http_writer.py
CodSpeed Performance Gauge
0%
1,001.9 µs997.1 µs
test_resolve_gitapi_subapps[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
0%
320.5 ms319 ms
test_read_one_hundred_websocket_text_messages[pyloop]
tests/test_benchmarks_http_websocket.py
CodSpeed Performance Gauge
0%
313.7 µs312.3 µs
test_web_response_with_text_body
tests/test_benchmarks_web_response.py
CodSpeed Performance Gauge
0%
661.7 µs658.8 µs
test_send_one_hundred_large_websocket_text_messages[pyloop]
tests/test_benchmarks_http_websocket.py
CodSpeed Performance Gauge
0%
539.7 µs537.3 µs
test_one_thousand_round_trip_websocket_binary_messages[pyloop]
tests/test_benchmarks_client_ws.py
CodSpeed Performance Gauge
0%
16.6 ms16.5 ms
test_one_thousand_round_trip_websocket_text_messages[pyloop]
tests/test_benchmarks_client_ws.py
CodSpeed Performance Gauge
0%
17 ms16.9 ms
test_resolve_gitapi_root[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
0%
2.1 ms2.1 ms
test_resolve_dynamic_resource_url_with_many_dynamic_routes[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
0%
3.7 ms3.7 ms
test_resolve_static_root_route[pyloop]
tests/test_benchmarks_web_urldispatcher.py
CodSpeed Performance Gauge
0%
1.1 ms1.1 ms
test_load_cookies_into_temp_cookiejar
tests/test_benchmarks_cookiejar.py
CodSpeed Performance Gauge
0%
206.9 µs206.4 µs
test_read_large_binary_websocket_messages[pyloop]
tests/test_benchmarks_http_websocket.py
CodSpeed Performance Gauge
0%
9.1 ms9.1 ms
test_get_request_with_251308_compressed_chunked_payload[pyloop]
tests/test_benchmarks_client.py
CodSpeed Performance Gauge
0%
465 ms465 ms
test_send_one_hundred_websocket_compressed_messages[pyloop]
tests/test_benchmarks_http_websocket.py
CodSpeed Performance Gauge
0%
3.3 ms3.3 ms
test_simple_web_stream_response
tests/test_benchmarks_web_response.py
CodSpeed Performance Gauge
0%
247.4 µs247.5 µs
test_one_hundred_get_requests_with_512kib_content_length_payload[pyloop]
tests/test_benchmarks_client.py
CodSpeed Performance Gauge
0%
166.7 ms166.8 ms
test_send_client_request_one_hundred[pyloop]
tests/test_benchmarks_client_request.py
CodSpeed Performance Gauge
0%
2.5 ms2.5 ms
test_one_hundred_simple_post_requests[pyloop]
tests/test_benchmarks_client.py
CodSpeed Performance Gauge
0%
37.3 ms37.3 ms
test_ten_web_middlewares[pyloop]
tests/test_benchmarks_web_middleware.py
CodSpeed Performance Gauge
0%
35.7 ms35.8 ms
test_one_thousand_large_round_trip_websocket_text_messages[pyloop]
tests/test_benchmarks_client_ws.py
CodSpeed Performance Gauge
0%
23.4 ms23.4 ms
test_send_one_hundred_websocket_text_messages_with_mask[pyloop]
tests/test_benchmarks_http_websocket.py
CodSpeed Performance Gauge
0%
808.1 µs809.9 µs
test_one_hundred_get_requests_with_30000_chunked_payload[pyloop]
tests/test_benchmarks_client.py
CodSpeed Performance Gauge
0%
40.9 ms41 ms
test_one_hundred_get_requests_with_30000_content_length_payload[pyloop]
tests/test_benchmarks_client.py
CodSpeed Performance Gauge
0%
39.5 ms39.6 ms
test_one_hundred_simple_get_requests_multiple_methods_route[pyloop]
tests/test_benchmarks_client.py
CodSpeed Performance Gauge
0%
32.5 ms32.6 ms
test_one_hundred_get_requests_with_1024_chunked_payload[pyloop]
tests/test_benchmarks_client.py
CodSpeed Performance Gauge
0%
37 ms37.1 ms
test_one_hundred_get_requests_with_1024_content_length_payload[pyloop]
tests/test_benchmarks_client.py
CodSpeed Performance Gauge
0%
35.6 ms35.7 ms
test_one_hundred_simple_get_requests[pyloop]
tests/test_benchmarks_client.py
CodSpeed Performance Gauge
0%
32.7 ms32.8 ms
test_send_one_hundred_websocket_text_messages[pyloop]
tests/test_benchmarks_http_websocket.py
CodSpeed Performance Gauge
0%
561.8 µs564.4 µs
test_create_client_request_with_headers[pyloop]
tests/test_benchmarks_client_request.py
CodSpeed Performance Gauge
0%
69.5 µs69.8 µs
test_client_request_update_cookies[pyloop]
tests/test_benchmarks_client_request.py
CodSpeed Performance Gauge
-1%
175.1 µs176 µs

Ignored

test_one_hundred_get_requests_with_512kib_chunked_payload[pyloop]
tests/test_benchmarks_client.py
Ignored
CodSpeed Performance Gauge
0%
168.1 ms168.2 ms

Commits

Click on a commit to change the comparison range
Base
master
7557b03
+16.75%
Fix race in FileResponse when the file is changed between the stat and open calls There was a race in ``FileResponse`` where the stat would be incorrect if the file was changed out between the `stat` and `open` syscalls. This would lead to various unexpected behaviors such as trying to read beyond the length of the file or sending a partial file. This problem is likely to occour when files are being renamed/linked into place. An example of how this can happen with a system that provides weather data every 60s: An external process writes `.weather.txt` at the top of each minute, and than renames it to `weather.txt`. In this case `aiohttp` may stat the old `weather.txt`, and than open the new `weather.txt`, and use the `stat` result from the original file. To fix this we now `fstat` the open file on operating systems where `fstat` is available fixes #8013
f053352
11 months ago
by bdraco
-0.98%
lint
e79d9c6
11 months ago
by bdraco
+0.51%
comments
2a41636
11 months ago
by bdraco
-0.97%
reverts
bdef0a9
11 months ago
by bdraco
+0.53%
comments
caeac0f
11 months ago
by bdraco
-0.41%
preen
2efe67f
11 months ago
by bdraco
+0.22%
Update CHANGES/10101.bugfix.rst
db087f2
11 months ago
by bdraco
+0.3%
Merge branch 'master' into race_wrong_stat
695e78c
11 months ago
by bdraco
© 2025 CodSpeed Technology
Home Terms Privacy Docs