Skip to content

Add timeout to space check to fix slow decompression while preserving safety#26

Merged
vlssu merged 5 commits intodevelopfrom
copilot/fix-extraction-performance-issue
Feb 12, 2026
Merged

Add timeout to space check to fix slow decompression while preserving safety#26
vlssu merged 5 commits intodevelopfrom
copilot/fix-extraction-performance-issue

Conversation

Copy link

Copilot AI commented Jan 19, 2026

Since v1.11.0, decompression has been extremely slow due to SpaceAvailableForDecompression() walking the entire archive before extraction begins. For large archives, this causes multi-minute delays and timeouts.

Changes

  • Added 5-second timeout to SpaceAvailableForDecompression() in compress.go
  • Restored upfront space check in postServerDecompressFiles with timeout protection
  • Enhanced error handling for both disk space and unknown archive format errors
  • Preserved disk quota protection via dual-layer approach:
    • Upfront validation for small/medium archives (completes < 5 seconds)
    • Incremental checks during extraction for large archives (timeout after 5 seconds)
    • HasSpaceFor() validates before each chunk write (compress.go:261)
    • Write() validates before each file creation (filesystem.go:156)
  • Improved request lifecycle handling by using c.Request.Context() for proper cancellation

Impact

Small/Medium Archives: Full upfront space validation completes quickly, preventing failed extractions before they start.

Large Archives: Space check times out after 5 seconds and decompression proceeds immediately with incremental space validation during extraction.

Request Cancellation: Proper cleanup when users cancel requests.

// Before: walks entire archive (could take minutes), then extracts
err := s.Filesystem().SpaceAvailableForDecompression(ctx, rootPath, file)
if err != nil { /* ... */ }
err = s.Filesystem().DecompressFile(ctx, rootPath, file)

// After: validates with 5-second timeout, then extracts
err := s.Filesystem().SpaceAvailableForDecompression(ctx, rootPath, file) // times out after 5s
if err != nil { /* handle space/format errors */ }
err = s.Filesystem().DecompressFile(ctx, rootPath, file) // with incremental checks

Testing

  • ✅ Build succeeded
  • ✅ All decompression tests pass (zip, rar, tar, tar.gz, GBK-encoded filenames)
  • ✅ Security scan completed - no vulnerabilities
  • ✅ Code review feedback addressed
Original prompt

貌似就是从 v1.11.0版本开始,解压缩文件出现很严重的问题,问题体现在解压特别慢,时间长到提示超时,但以前解压都是很快的


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 19, 2026 16:20
Co-authored-by: vlssu <43847794+vlssu@users.noreply.github.com>
Co-authored-by: vlssu <43847794+vlssu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix slow extraction issue starting from v1.11.0 Remove expensive upfront archive scan blocking decompression Jan 19, 2026
Copilot AI requested a review from vlssu January 19, 2026 16:27
@vlssu
Copy link
Member

vlssu commented Jan 19, 2026

@copilot 有什么办法保留检查空间是否足够还能解决解压缓慢的问题

Copilot AI and others added 2 commits January 19, 2026 23:50
Co-authored-by: vlssu <43847794+vlssu@users.noreply.github.com>
Co-authored-by: vlssu <43847794+vlssu@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 19, 2026

@copilot 有什么办法保留检查空间是否足够还能解决解压缓慢的问题

已实现!我添加了一个5秒超时机制来平衡性能和安全性:

小型/中型压缩包(< 5秒完成):

  • ✅ 完整的空间检查在解压前完成
  • ✅ 如果空间不足,立即返回错误

大型压缩包(需要 > 5秒):

  • ⏱️ 空间检查在5秒后超时
  • ✅ 解压立即开始
  • ✅ 在解压过程中对每个文件进行增量空间检查

这样既解决了解压缓慢的问题,又保留了空间检查功能。相关改动见提交 8c035e7

Copilot AI changed the title Remove expensive upfront archive scan blocking decompression Add timeout to space check to fix slow decompression while preserving safety Jan 19, 2026
@vlssu vlssu marked this pull request as ready for review February 12, 2026 11:16
@vlssu vlssu merged commit 86fabec into develop Feb 12, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants