Fix: Clear the file transfer session when its sub-connection drops
A file transfer session holds raw pointers to its file-manager and stream sub-connections, but nothing on the offline path looked at them. OfflineProc cleans up terminal, remote-control and chat sessions and skipped file transfers entirely, so a client that disconnected in the middle of a transfer left the session pointing at a context that went back to the connection pool. When the tool thread timed out it called CancelIO on that stale pointer, which could cancel somebody else's connection. Add a context-to-device table next to the sessions, kept under the same mutex and erased by ClearFileTransfer so a recycled pointer is never mistaken for a live one. OfflineProc now calls OnFileTransferContextClosed, which drops both pointers. A dropped stream sub-connection means the transfer cannot complete, so it also fails the session with error 1003 and wakes the waiting thread; the file-manager sub-connection only issues the command and its loss is not treated as a failure of the transfer itself. Verified against the debug client: killing it 1.2 s into a 500 MB download returns "Connection lost: the transfer sub-connection closed" after about 1 s instead of waiting out timeout_ms, and the server stays up. After the client restarts, two consecutive downloads and one upload still work. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
39f0928de7
commit
16f23e164c
4 files changed
+49
-2
No files matched your search
@@ -278,6 +278,11 @@ public:
|
||||
// 收尾:擦会话 + 锁外 CancelIO 文件管理器/流式两条子链接(幂等)。
|
||||
void ClearFileTransfer(uint64_t device_id);
|
||||
|
||||
// 文件传输子链接断开(OfflineProc 调用):清反查表 + 置空裸指针,避免工具线程超时路径
|
||||
// 对已回收(连接池复用)的 context 误 CancelIO。流式子链接断开 = 传输失败(1003);
|
||||
// 文件管理器子链接断开只是少了收尾对象,传输数据走流式子链接,不判失败。
|
||||
void OnFileTransferContextClosed(context* subCtx);
|
||||
|
||||
// ===== P7:设备管理控制(kill_process / operate_window / control_service / power_action)=====
|
||||
// 写工具复用 m_Pending 单飞行;followUp/followUpSent/subCtx 标记接管进度。
|
||||
// 「就绪 token」与「确认 token」是同一 token(客户端子连接构造即回一包,写后再回一包),
|
||||
@@ -572,7 +577,7 @@ private:
|
||||
uint32_t directoryCount = 0; // 目录项计数(目录不发 COMPLETE 包)
|
||||
uint32_t filesDone = 0; // 已完成的文件数(含跳过的)
|
||||
bool done = false; // 全部完成或出错
|
||||
int error = 0; // 0=ok;8=哈希不匹配;1001=路径逃逸;1002=超时
|
||||
int error = 0; // 0=ok;8=哈希不匹配;1001=路径逃逸;1002=超时;1003=流式子连接断线
|
||||
std::map<uint32_t, FileTransferEntry> fileEntries; // fileIndex → {path,size,sha256}
|
||||
std::set<uint32_t> skipIndexes; // overwrite=false 跳过的 fileIndex
|
||||
std::vector<FileTransferEntry> skipped; // 跳过的文件(供输出)
|
||||
@@ -581,6 +586,8 @@ private:
|
||||
std::mutex m_FileXferMutex;
|
||||
std::condition_variable m_FileXferCv;
|
||||
std::map<uint64_t, FileTransferSession> m_FileXferSessions; // device_id → 会话
|
||||
// 子连接反查(受 m_FileXferMutex 保护):OfflineProc 拿不到 device_id,只能按 context* 找会话。
|
||||
std::map<context*, uint64_t> m_FileXferContextToDevice;
|
||||
|
||||
// ===== P9:远程交谈(受 m_ChatMutex 保护;单设备单会话)=====
|
||||
// 用 shared_ptr 持有会话:chat_wait / chat_send 在工作线程里复制一份后,即使 map 条目
|
||||
|
||||
Reference in new issue
Block a user