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:
yuanyuanxianganddeepseek-flash committed 2026-10-25 14:20:13 +01:00
1 parent 39f0928de7
commit 16f23e164c
4 files changed
+49 -2

No files matched your search

+6
View File
@@ -5546,6 +5546,12 @@ BOOL CALLBACK CMy2015RemoteDlg::OfflineProc(CONTEXT_OBJECT* ContextObject)
McpServer().OnManagedContextClosed(ContextObject);
}
// MCP P6 文件传输的文件管理器/流式子连接断开:清反查表并置空裸指针,避免工具线程
// 超时路径对连接池回收后的 context 误 CancelIO;流式子链接断开同时判传输失败。
if (McpServer().IsRunning()) {
McpServer().OnFileTransferContextClosed(ContextObject);
}
// MCP P9 远程交谈:子连接(或主连接)断开时清路由/标记会话 closed 并唤醒 chat_wait。
// 同样必须在 RemoveFromHostList 之前,避免连接池复用同一 context 指针后误路由。
if (McpServer().IsRunning()) {