[PR #1036] [MERGED] Fix race condition in folder download causing NotSupportedException #3871

Closed
opened 2026-03-13 13:02:34 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/1Remote/1Remote/pull/1036
Author: @Copilot
Created: 11/21/2025
Status: Merged
Merged: 11/22/2025
Merged by: @VShawn

Base: mainHead: copilot/fix-folder-download-exception


📝 Commits (3)

  • 43941a3 Initial plan
  • 1912df6 Fix folder download by making ScanTransmitItems async
  • d07d45b Remove unnecessary status backup/restore pattern

📊 Changes

1 file changed (+4 additions, -6 deletions)

View changed files

📝 Ui/Model/Protocol/FileTransmit/Transmitters/TransmissionController/TransmitTask.cs (+4 -6)

📄 Description

When downloading a folder via CmdDownload, AddServerDirectory() was called without await, causing it to return immediately while still scanning recursively. This created a race where transmission could complete before scanning finished, leading to NotSupportedException when the background scan tried to add items to an already-transmitted task.

Changes

  • Made ScanTransmitItems() async and properly await AddServerDirectory()
  • Updated StartTransmitAsync() to await the now-async ScanTransmitItems()
  • Changed Task.Factory.StartNew to Task.Run for correct async lambda handling
  • Removed obsolete status backup/restore pattern around the awaited call
- private void ScanTransmitItems()
+ private async Task ScanTransmitItems()
  {
      // ...
      if (item.IsDirectory)
      {
-         var bk = TransmitTaskStatus;
-         AddServerDirectory(item);
-         TransmitTaskStatus = bk;
+         await AddServerDirectory(item);
      }
  }

The fix ensures directory scanning completes before transmission begins, eliminating the race condition.

Original prompt

VmFileTransmitHost.cs 当在界面选中一个文件夹,执行 CmdDownload 命令时,应当将该文件夹及其内部所有文件按原始文件结构,从SFTP服务器下载到到本地。但目前执行程序时,最终会在 TransmitTask.cs 的 AddTransmitItem 函数中,因为 TransmitTaskStatus == ETransmitTaskStatus.Transmitted 而抛出异常:throw new NotSupportedException();。

你应理解上述 CmdDownload 的目标功能,并阅读所有相关代码,找到当前下载文件夹出错的原因并改正。


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/1Remote/1Remote/pull/1036 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 11/21/2025 **Status:** ✅ Merged **Merged:** 11/22/2025 **Merged by:** [@VShawn](https://github.com/VShawn) **Base:** `main` ← **Head:** `copilot/fix-folder-download-exception` --- ### 📝 Commits (3) - [`43941a3`](https://github.com/1Remote/1Remote/commit/43941a3a9708fff0bf8020da8465d30d72c69632) Initial plan - [`1912df6`](https://github.com/1Remote/1Remote/commit/1912df6be9613afee91b0b384155a0296764bcf4) Fix folder download by making ScanTransmitItems async - [`d07d45b`](https://github.com/1Remote/1Remote/commit/d07d45b4f00f8fb295caee8d728a881d3a09ffc9) Remove unnecessary status backup/restore pattern ### 📊 Changes **1 file changed** (+4 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `Ui/Model/Protocol/FileTransmit/Transmitters/TransmissionController/TransmitTask.cs` (+4 -6) </details> ### 📄 Description When downloading a folder via CmdDownload, `AddServerDirectory()` was called without `await`, causing it to return immediately while still scanning recursively. This created a race where transmission could complete before scanning finished, leading to `NotSupportedException` when the background scan tried to add items to an already-transmitted task. ### Changes - Made `ScanTransmitItems()` async and properly await `AddServerDirectory()` - Updated `StartTransmitAsync()` to await the now-async `ScanTransmitItems()` - Changed `Task.Factory.StartNew` to `Task.Run` for correct async lambda handling - Removed obsolete status backup/restore pattern around the awaited call ```diff - private void ScanTransmitItems() + private async Task ScanTransmitItems() { // ... if (item.IsDirectory) { - var bk = TransmitTaskStatus; - AddServerDirectory(item); - TransmitTaskStatus = bk; + await AddServerDirectory(item); } } ``` The fix ensures directory scanning completes before transmission begins, eliminating the race condition. <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > VmFileTransmitHost.cs 当在界面选中一个文件夹,执行 CmdDownload 命令时,应当将该文件夹及其内部所有文件按原始文件结构,从SFTP服务器下载到到本地。但目前执行程序时,最终会在 TransmitTask.cs 的 AddTransmitItem 函数中,因为 TransmitTaskStatus == ETransmitTaskStatus.Transmitted 而抛出异常:throw new NotSupportedException();。 > > 你应理解上述 CmdDownload 的目标功能,并阅读所有相关代码,找到当前下载文件夹出错的原因并改正。 </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-13 13:02:34 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/1Remote#3871
No description provided.