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
@@ -400,3 +400,4 @@ int n = RecvFileChunkV2((char*)szBuffer, ulLength, m_conn, nullptr, m_hash, m_hm
|
||||
| # | 问题 | 修复 |
|
||||
|---|---|---|
|
||||
| R1 | **纯目录树下载必超时**:完成判定 `filesDone >= totalFiles - directoryCount` 只在 `OnFileCompleteV2` 里跑,而客户端对目录项不发 `COMMAND_FILE_COMPLETE_V2`。空目录/只有子目录的树期望文件数为 0,永远等不到 COMPLETE → 只能干等 `timeout_ms`(默认 600s)后报 `1002` | `OnFileChunkV2` 的目录分支里,`directoryCount >= totalFiles`(即全部条目都是目录)时直接置 `done` + notify。实测空目录 0.2s 返回、3 文件目录树回归正常 |
|
||||
| R2 | **断线无清理 → 悬空子连接指针**:`FileTransferSession.fmSubCtx / streamSubCtx` 是裸 `context*`,`OfflineProc` 只清了终端/远程控制/聊天,没有文件传输的钩子(§6.5 声称的「断线擦会话」实现缺失)。客户端传输中掉线后 connection 被连接池回收,工具线程超时路径仍对其 `CancelIO()` → 悬空指针/误取消他人连接 | 新增 `m_FileXferContextToDevice` 反查表(受 `m_FileXferMutex` 保护,`ClearFileTransfer` 同步擦除),`OfflineProc` 增 `OnFileTransferContextClosed`:清指针并移除反查项;**流式子连接**断开即判失败(`error=1003`,立即唤醒工具线程),文件管理器子连接断开只清指针(数据走流式子连接,不判失败)。实测传输中杀掉客户端:1s 返回 `Connection lost`(原来要等满 `timeout_ms`),服务端存活;重启客户端后连续两次下载、一次上传均正常 |
|
||||
Reference in new issue
Block a user