Skip to content

Commit 37d99bb

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 f02f24c commit 37d99bb

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
@@ -1535,17 +1535,20 @@ async fn upload_task(
15351535
if eof_seen.load(Ordering::Relaxed) { break; }
15361536
let now = tokio::time::Instant::now();
15371537
if now >= deadline { break; }
1538-
if data.len() >= 1024 * 1024 { break; } // 1MB cap
1538+
if data.len() >= 256 * 1024 { break; } // 256KB cap
15391539
let remaining = deadline - now;
1540-
match tokio::time::timeout(remaining, reader.read(&mut buf)).await {
1540+
// Cap per-read wait at 10ms: if no data for 10ms (gap
1541+
// between video chunk and heartbeat), send what we have.
1542+
let read_timeout = Duration::from_millis(10).min(remaining);
1543+
match tokio::time::timeout(read_timeout, reader.read(&mut buf)).await {
15411544
Ok(Ok(0)) => {
15421545
upload_closed.store(true, Ordering::Release);
15431546
break;
15441547
}
15451548
Ok(Ok(more_n)) => {
15461549
data.extend_from_slice(&buf[..more_n]);
15471550
// Extend window if we hit 32KB threshold
1548-
if !extended && data.len() >= 32 * 1024 {
1551+
if !extended && data.len() >= 8 * 1024 {
15491552
deadline = tokio::time::Instant::now() + Duration::from_secs(1);
15501553
extended = true;
15511554
}

0 commit comments

Comments
 (0)