fix: close response bodies on non-OK responses - #5817
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughThree functions ( HTTP Response Body Leak Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
4e61e5d to
5839d84
Compare
Important
📝 变更描述 / Description
部分 HTTP 请求路径在
client.Do(req)成功后,会先判断上游响应状态码是否为 200,再延后执行defer resp.Body.Close()。如果上游可达但返回 401、429、500 等非 200 响应,函数会直接返回错误,导致该响应体没有及时关闭。本 PR 将这些路径的
defer resp.Body.Close()移到确认client.Do成功之后,保证后续所有错误返回分支都会关闭 response body。覆盖的路径包括:
同时补充了 Suno 轮询的回归测试:构造一个返回 500 的 fake response body,断言函数返回错误时仍会调用
Close()。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
Summary by CodeRabbit