Skip to content

[build-tools] Wait up to 90 seconds for the first ngrok tunnel open - #5001

Closed
szdziedzic wants to merge 1 commit into
mainfrom
szdziedzic/ngrok-first-open-timeout
Closed

szdziedzic wants to merge 1 commit into
mainfrom
szdziedzic/ngrok-first-open-timeout

Conversation

@szdziedzic

@szdziedzic szdziedzic commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Why

Since 11:50 UTC on 30 Nov, ngrok tunnel opens for device run sessions are often slow. Before that, the slowest open in each 10 minutes took 0.5–0.7 s. During the incident, about 1 in 6 opens did not finish within our timeout. At least 14 iOS sessions failed with Ngrok tunnel open timed out after 19000ms before the simulator became available.

The late_open metric shows when a timed-out open finally finishes. On 30 Nov, slow opens finished after 64–77 s on average, and the slowest took 142 s. In four earlier episodes (27 Nov, 28 Nov, 30 Nov 00:00 UTC), the slowest open took about 75.5 s each time. So a 19 s first-open timeout fails sessions whose tunnel would open a minute later.

How

  • Raise FIRST_OPEN_TIMEOUT_MS in ngrokTunnel.ts from 19 s to 90 s. Retries and reopens keep their 15 s timeout.
  • Add INITIAL_OPEN_MAX_DURATION_MS (123 s): the first open plus both retries and their delays.
  • The preview tunnel's opening limit in deviceSessionHost.ts was the host's timeoutMs (60 s for agent-device, web preview and Argent). It is now the larger of timeoutMs and INITIAL_OPEN_MAX_DURATION_MS. STARTUP_TIMEOUT_MS does not change, so the daemon and readiness waits keep their limits.

All tunnels get the longer first open: web-preview, agent-device, egress, Argent and Appium. Only the preview tunnel had an outer limit. The CLI's 120 s local egress limit starts after the session is ready, so it does not overlap the egress tunnel's first open.

Trade-off: when an open never finishes, the session now fails after about 90 s instead of about 20 s. On normal days opens take less than 1 s, so nothing changes.

Test Plan

  • New: a first open that settles after 75 s is kept (ngrokTunnel.test.ts).
  • New: the preview tunnel waits past the host time-out, then fails on the tunnel time-out and closes the late listener (deviceSessionHost.test.ts). This replaces the opening timeout case of the shared cleanup test: the host's preview limit no longer fires while the ngrok open is pending, so cleanup does not wait for it.
  • Updated the tests that used the 19 s value to use FIRST_OPEN_TIMEOUT_MS.
  • yarn jest-unit in packages/build-tools: 3290 passed, 8 skipped.
  • yarn fmt:check, yarn lint, yarn typecheck pass.
  • No live tunnel test. After the deploy, check that expo.www.eas.device_run_session.ngrok_tunnel.late_open stays near zero during slow periods and that sessions stop failing with Ngrok tunnel open timed out.

🤖 Generated with Claude Code


Devin Review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ Thank you for adding a changeset!

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

// settles. The first open waits longer instead, and keeps a listener that arrives late.
// An open usually takes less than 1 second. When ngrok is slow, most slow opens finish after
// about 75 seconds, so the first open waits for them instead of failing the session.
export const FIRST_OPEN_TIMEOUT_MS = 90_000;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Queued opens share the startup budget

Cold agent-device startup waits for both tunnels, but openAsync starts timing before ngrok acquires its shared lock. The single-tunnel test misses time spent behind a slow first open.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.91%. Comparing base (49e2b64) to head (1d748c8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5001      +/-   ##
==========================================
+ Coverage   77.91%   77.91%   +0.01%     
==========================================
  Files        1146     1146              
  Lines       58697    58701       +4     
  Branches    13045    13045              
==========================================
+ Hits        45728    45732       +4     
+ Misses      12849    11990     -859     
- Partials      120      979     +859     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@szdziedzic szdziedzic closed this Nov 30, 2026
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.

1 participant