Repository navigation
fix(httpweb): resolve pending request future on disconnect - #808
Conversation
Reviewer's GuideUpdates HTTPSClientEx to fail pending request futures on disconnect and atomically prevent timeout, disconnect, and late-response paths from completing the promise more than once. Adds a local-server regression test confirming canceled/disconnected requests no longer leave synchronous callers blocked indefinitely. Sequence diagram for resolving HTTP requests on disconnectsequenceDiagram
participant Caller as FileClient::downloadFile
participant Client as HTTPSClientEx
participant Connection as HTTPSConnection
participant Future as RequestFuture
Caller->>Client: SendRequest(request)
Client->>Future: create pending promise
Client->>Connection: send request
Connection--xClient: onDisconnected()
Client->>Connection: Cancel timeout
Client->>Client: SetPromiseError(Disconnected!)
Client->>Future: set_exception
Future-->>Caller: future.get() throws
alt late response or timeout
Client->>Client: SetPromiseValue(response) or SetPromiseError(error)
Client-->>Client: return because promise already completed
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, re2zero The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
c247b1f to
95bb6c7
Compare
4e98d8f to
8e31bef
Compare
95bb6c7 to
61297ad
Compare
8e31bef to
5e03963
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无需修改'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['在测试中使用 RAII scope guard(如 struct ServiceGuard { std::shared_ptr& svc; ~ServiceGuard() { svc->Stop(); } } guard{service};)或改用 gtest fixture 的 TearDown() 方法,确保 service->Stop() 在任何路径下都被调用'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无需修改'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['无需修改'] 💡 改进建议代码示例// tests/manager/httpclient_test.cpp — 使用 RAII 守卫确保清理
TEST(HTTPClientExTest, DisconnectResolvesPendingRequest)
{
QTcpServer server;
ASSERT_TRUE(server.listen(QHostAddress::LocalHost, 0));
QObject::connect(&server, &QTcpServer::newConnection, &server, [&server] {
while (QTcpSocket *socket = server.nextPendingConnection())
socket->abort();
});
auto service = std::make_shared<AsioService>();
service->Start();
// RAII guard: ensures service->Stop() is always called,
// even if an ASSERT_* fails and returns early.
struct ServiceGuard {
std::shared_ptr<AsioService>& svc;
~ServiceGuard() { svc->Stop(); }
} guard{service};
auto client = std::make_shared<NetUtil::HTTP::HTTPSClientEx>(
service, SecureConfig::clientContext(),
"127.0.0.1", server.serverPort());
auto future = client->SendGetRequest("download/payload.txt&token=test",
BaseKit::Timespan::seconds(30));
for (int i = 0; i < 50
&& future.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready;
++i) {
QTest::qWait(100);
}
ASSERT_EQ(future.wait_for(std::chrono::milliseconds(0)), std::future_status::ready);
EXPECT_THROW(future.get(), std::runtime_error);
client->DisconnectAsync();
client.reset();
// service->Stop() 由 ServiceGuard 析构自动调用
}本报告由 AI 代码审查工具自动生成 |
HTTPSClientEx canceled its timeout timer on disconnect without completing the request promise. FileClient::downloadFile() could then block forever in future::get(), and FileClient's destructor froze the GUI while joining the download thread on cancel. Fail the pending promise on disconnect and guard promise completion so a late response cannot satisfy it twice. Log: resolve pending request future on disconnect PMS: TASK-396845 Influence: cancelling a download no longer blocks the GUI while joining the download thread.
61297ad to
4dc4ef9
Compare
Part 5/8 of the reverse tunnel stack (recovery of #801).
This reapplies the reviewed commit on top of the corrected stack because #801 was accidentally merged into its stacked base branch instead of master.
Merge order: #805 → #806 → #807 → #808 → #809 → #810 → #811.
Retargeted to master after #807 merged.
HTTPSClientEx canceled its timeout timer on disconnect without completing
the request promise. FileClient::downloadFile() could then block forever
in future::get(), and FileClient's destructor froze the GUI while joining
the download thread on cancel.
Fail the pending promise on disconnect and guard promise completion so a
late response cannot satisfy it twice.
Log: resolve pending request future on disconnect
PMS: TASK-396845
Influence: cancelling a download no longer blocks the GUI while joining the download thread.
Summary by Sourcery
Ensure disconnected HTTPS requests terminate promptly so canceled downloads do not freeze the application.
Bug Fixes:
Tests: