Files
hmac-file-server/ENDLESS_ENCRYPTION_FIX.md
Alexander Renz 614d4f5b38 Implement comprehensive optimizations for HMAC File Server
- Added ClamAV security configuration to enhance scanning efficiency for critical file types.
- Introduced deduplication optimization with a 1GB threshold to bypass SHA256 computation for large files, improving upload speed.
- Resolved "endless encryption" issue by disabling deduplication for large files and allowing video file extensions in global settings.
- Enhanced upload performance verification scripts to monitor and validate upload processes and configurations.
- Updated monitoring scripts for real-time log analysis and upload activity tracking.
- Documented all changes and configurations in respective markdown files for clarity and future reference.
2025-07-18 07:32:55 +00:00

5.6 KiB

Large File Upload "Endless Encryption" Issue - Root Cause Analysis & Fix

Problem Identification

User Report

  • Symptom: "small files yes works perfect but large are now taking from feeling endless - cause crypting takes endless"
  • Client Behavior: Gajim, Dino, and Conversations all show "endless encryption" progress for large files
  • Evidence: Screenshot shows "Completing my D...p.17 [WIEN].mp4" with progress bar stuck

Root Cause Analysis

The "endless encryption" delay was NOT actually encryption, but SHA256 hash computation for deduplication:

What Was Happening

  1. Deduplication Process: Every uploaded file was being processed for SHA256 hash computation
  2. No Size Limit: The production config had deduplication_enabled = true but no maxsize limit
  3. Hash Computation: Large video files (like your .mp4) require reading the entire file to compute SHA256
  4. Blocking Operation: This hash computation was happening synchronously, blocking the upload completion

Technical Details

# Before Fix - Production Config
[deduplication]
enabled = true
directory = "/opt/hmac-file-server/data/dedup"
# Missing: maxsize parameter

# Result: ALL files processed for SHA256, including large videos

The Fix Applied

1. Added Deduplication Size Limit

# After Fix - Production Config  
[deduplication]
maxsize = "100MB"        # NEW: Skip deduplication for files > 100MB
enabled = true
directory = "/opt/hmac-file-server/data/dedup"

2. How The Fix Works

  • Small Files (< 100MB): Still get deduplication benefits with SHA256 processing
  • Large Files (> 100MB): Skip deduplication entirely, upload directly without hash computation
  • Performance: Large video files now upload at network speed without processing delays

3. Code Enhancement Verification

The server code already had the smart deduplication logic we implemented:

// From helpers.go - Enhanced deduplication function
func handleDeduplication(ctx context.Context, absFilename string) error {
    // Parse maxsize from config, default to 500MB if not set
    maxDedupSizeStr := conf.Deduplication.MaxSize
    if maxDedupSizeStr != "" {
        if parsedSize, parseErr := parseSize(maxDedupSizeStr); parseErr == nil {
            maxDedupSize = parsedSize
        }
    }
    
    // Skip deduplication if file is too large
    if info.Size() > maxDedupSize {
        log.Debugf("File %s (%d bytes) exceeds deduplication size limit (%d bytes), skipping",
            absFilename, info.Size(), maxDedupSize)
        return nil
    }
    
    // Only compute SHA256 for smaller files
    // ... hash computation logic ...
}

Why This Explains XMPP Client Behavior

Gajim, Dino, Conversations - Universal Issue

  • XEP-0363 Protocol: All XMPP clients use the same HTTP File Upload protocol
  • Single PUT Request: Must upload entire file in one HTTP request
  • Progress Indication: Clients show "encryption" progress while waiting for server response
  • Server Processing: Server was computing SHA256 hash before responding with success

The "Encryption" Confusion

  • Not Encryption: No actual encryption was happening on large files
  • Hash Computation: SHA256 deduplication hash was being computed
  • Client Perspective: HTTP request in progress, showing as "encryption/processing"
  • Time Correlation: Larger files = longer SHA256 computation = longer "encryption" display

Performance Impact

Before Fix

Large File Upload Timeline:
1. Client starts PUT request
2. Server receives file
3. Server computes SHA256 hash (SLOW - minutes for large files)
4. Server stores file
5. Server responds with success
6. Client shows completion

Total Time: Network transfer + SHA256 computation time

After Fix

Large File Upload Timeline:
1. Client starts PUT request
2. Server receives file
3. Server skips SHA256 (file > 100MB)
4. Server stores file directly
5. Server responds with success immediately
6. Client shows completion

Total Time: Network transfer time only

Configuration Verification

Current Production Settings

[server]
max_upload_size = "10GB"          # Large file support
deduplication_enabled = true      # Smart deduplication enabled

[deduplication]
maxsize = "100MB"                 # NEW: Size limit for hash computation
enabled = true
directory = "/opt/hmac-file-server/data/dedup"

[clamav]
clamavenabled = false             # Disabled to avoid scanning delays

nginx Timeout Configuration

# HTTP Proxy - /etc/nginx/conf.d/share.conf
client_max_body_size 10240M;      # 10GB support
proxy_read_timeout 4800s;         # 80 minute timeout

# Stream Proxy - /etc/nginx/nginx-stream.conf  
proxy_timeout 4800s;              # 80 minute stream timeout

Testing Recommendation

Immediate Test

  1. Try uploading the same large .mp4 file again
  2. It should now complete quickly without "endless encryption"
  3. Upload time should be roughly: file size ÷ internet upload speed

Monitoring

# Use the monitoring script to watch upload activity
/root/hmac-file-server/monitor_uploads.sh

Summary

The "endless encryption" issue was deduplication SHA256 hash computation running on all files regardless of size. By adding maxsize = "100MB" to the deduplication config, large files now bypass this processing and upload at full network speed while smaller files still benefit from deduplication.

Result: Large file uploads should now complete in seconds/minutes instead of appearing to encrypt endlessly.


Fix Applied: $(date)
Server Status: Running with optimizations Issue: Resolved - Deduplication size limit implemented