Observatory port timeout on iOS
Problem
I'm unable to debug a freshly created app on physical iOS devices when pubspec dependencies reach a certain size, because it causes the "waiting for observatory port" step to timeout after 30 seconds. Devices tested: iPhone 8 iPhone 12 iPhone 12 Pro iOS versions tested: 14.2 14.2.1 14.3 Xcode versions tested: 12.2 12.3 Tests run using MacOS Catalina 10.15.7 on a late 2019 MBP 16". Simply commenting out random pubspec dependencies from the below, cleaning and rebuilding allows debugging to attach - sometimes just barely, at the 28 second or 29 second mark. Here's a triggering pubspec: [code block]
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Increase Observatory Timeout for iOS Debugging
The 'waiting for observatory port' timeout occurs due to the large size of pubspec dependencies, which causes the app to take longer to initialize and bind the observatory port. The default timeout is set to 30 seconds, which is insufficient for larger apps, especially on physical devices with limited resources.
Awaiting Verification
Be the first to verify this fix
- 1
Modify Flutter Tool Timeout
Increase the timeout duration for the observatory port by setting the environment variable 'FLUTTER_OBSERVATORY_PORT_TIMEOUT' to a higher value, such as 60 seconds.
bashexport FLUTTER_OBSERVATORY_PORT_TIMEOUT=60 - 2
Clean Flutter Build
Run the Flutter clean command to remove any old build artifacts that may be causing issues.
bashflutter clean - 3
Rebuild the App
Rebuild the app to ensure that all dependencies are correctly linked and the new timeout setting is applied.
bashflutter run - 4
Monitor Debugging Process
Observe the debugging process to ensure that the app attaches successfully within the new timeout period. If it still fails, consider further optimizing dependencies.
- 5
Optimize Dependencies
Review and optimize the pubspec dependencies to reduce the overall size of the app. Remove any unnecessary packages or replace heavy packages with lighter alternatives.
Validation
Confirm the fix worked by successfully attaching the debugger to the app within the new timeout period. If the debugger attaches without timing out, the issue is resolved. Additionally, check for any performance improvements in the app startup time.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep