Fix: 修复 aiohttp 流式响应分块大小不固定问题#3919
Merged
yanyongyu merged 4 commits intononebot:masterfrom Mar 27, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3919 +/- ##
==========================================
+ Coverage 93.77% 93.78% +0.01%
==========================================
Files 48 48
Lines 4351 4360 +9
==========================================
+ Hits 4080 4089 +9
Misses 271 271
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
|
🚀 Deployed to https://deploy-preview-3919--nonebot2.netlify.app |
Member
|
个人认为大概率是测试代码的问题,分包大小只保证不超过最大值是普遍符合预期的行为 |
yanyongyu
previously approved these changes
Mar 26, 2026
Contributor
Author
|
那我把test改成小于等于? |
Member
|
应该不用,这么修也不是不行 |
yanyongyu
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
环境配置
python版本:python3.12.12
操作系统: macOS 26.2 25C56 arm64
问题复现
代码拉下来跑了一下pytest

test failed,说是返回的块大小不一定等于chunk_size
原因分析
原来的代码是:
而iter_chunked底层调用的是_read_nowait,注解里写的是“Read not more than n bytes”,所以chunk大小可能小于chunk_size
解决方案
现在改成,手动写一个buffer,池子里chunk的大小大于等于要求的chunk_size的时候就截断并yield出去,结束后再把buffer里的yield出去
最后一块chunked可能小于chunk_size的情况我并未处理,如果需要的话我可以补到chunk_size大小
测试
已通过全部测试
