Skip to content

Commit bb104d0

Browse files
vahidlazioclaude
andcommitted
fix(tunnel): 256KB upload cap, 10ms gap timeout, 8KB extend threshold
Reduces upload chunk size to prevent large video uploads from starving heartbeat polls in shared batches. Adaptive accumulation: - 50ms initial window, 10ms per-read gap timeout - >= 8KB triggers extended 1s window (capped at 256KB) - Smaller chunks clear batches faster, heartbeats get through Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4d5790f commit bb104d0

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/tunnel_client.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,17 +1512,20 @@ async fn upload_task(
15121512
if eof_seen.load(Ordering::Relaxed) { break; }
15131513
let now = tokio::time::Instant::now();
15141514
if now >= deadline { break; }
1515-
if data.len() >= 1024 * 1024 { break; } // 1MB cap
1515+
if data.len() >= 256 * 1024 { break; } // 256KB cap
15161516
let remaining = deadline - now;
1517-
match tokio::time::timeout(remaining, reader.read(&mut buf)).await {
1517+
// Cap per-read wait at 10ms: if no data for 10ms (gap
1518+
// between video chunk and heartbeat), send what we have.
1519+
let read_timeout = Duration::from_millis(10).min(remaining);
1520+
match tokio::time::timeout(read_timeout, reader.read(&mut buf)).await {
15181521
Ok(Ok(0)) => {
15191522
upload_closed.store(true, Ordering::Release);
15201523
break;
15211524
}
15221525
Ok(Ok(more_n)) => {
15231526
data.extend_from_slice(&buf[..more_n]);
15241527
// Extend window if we hit 32KB threshold
1525-
if !extended && data.len() >= 32 * 1024 {
1528+
if !extended && data.len() >= 8 * 1024 {
15261529
deadline = tokio::time::Instant::now() + Duration::from_secs(1);
15271530
extended = true;
15281531
}

0 commit comments

Comments
 (0)