Skip to content

[flutter_tools] Handle HttpException during VM service connection - #191182

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
bkonyi:crash-dds-http-connection-closed
Aug 19, 2026
Merged

auto-submit[bot] merged 3 commits into
flutter:masterfrom
bkonyi:crash-dds-http-connection-closed

Conversation

@bkonyi

@bkonyi bkonyi commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

This PR handles io.HttpException thrown during the VM service connection process in flutter_tools.

Problem

When connecting to the VM service, if the server closes the HTTP connection prematurely (e.g., "Connection closed before full header was received"), io.WebSocket.connect throws an io.HttpException. This exception was not caught in _defaultOpenChannel in vmservice.dart, causing the connection loop to terminate abruptly with an unhandled exception and crashing the tool.

Fix

  • Added io.HttpException to the caught exceptions in _defaultOpenChannel (vmservice.dart), ensuring connection attempts retry with exponential backoff rather than crashing.
  • Added unit test in vmservice_test.dart verifying retry messages and logging behavior when io.HttpException is encountered during connection.

Fixes #191178

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Aug 16, 2026
@bkonyi bkonyi added the CICD Run CI/CD label Aug 16, 2026
Catches io.HttpException in _defaultOpenChannel to retry connection when the server closes the HTTP upgrade connection prematurely, preventing unhandled exceptions and tool crashes.

Fixes flutter#191178
@bkonyi
bkonyi force-pushed the crash-dds-http-connection-closed branch from a49af98 to 7c54eae Compare August 17, 2026 18:08
@bkonyi bkonyi changed the title [flutter_tools] Handle HttpException during VM service connection and complete errors with Exception [flutter_tools] Handle HttpException during VM service connection Aug 17, 2026
@bkonyi
bkonyi requested a review from chingjun August 17, 2026 18:38
@bkonyi
bkonyi marked this pull request as ready for review August 17, 2026 18:38

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds handling for io.HttpException during VM Service connection attempts, ensuring these exceptions are caught and retried, and includes a new unit test to verify this behavior. The review feedback suggests simplifying the exception handling by catching the base io.IOException instead of maintaining separate, identical catch blocks for io.SocketException, io.HttpException, and io.WebSocketException.

Comment on lines 151 to 155
} on io.SocketException catch (e) {
await handleError(e);
} on io.HttpException catch (e) {
await handleError(e);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since both io.SocketException and io.HttpException (as well as io.WebSocketException caught in the preceding block) are subclasses of io.IOException and are handled identically by calling await handleError(e);, we can simplify these catch blocks by catching io.IOException instead.

This reduces code duplication and makes the connection logic more robust against other potential I/O-related exceptions during connection. You can also safely remove the preceding on io.WebSocketException catch block as it is now subsumed by io.IOException.

    } on io.IOException catch (e) {
      await handleError(e);
    }
References
  1. Suggest simplification and refactoring: Assess whether the code can be made simpler or refactored to enhance readability and maintainability. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to catch io.IOException directly, simplifying the catch block.

Catches io.IOException in _defaultOpenChannel to handle all I/O and connection-related exceptions (including WebSocketException, SocketException, and HttpException) uniformly.
@bkonyi bkonyi added CICD Run CI/CD and removed CICD Run CI/CD labels Aug 17, 2026
@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 18, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 18, 2026
@auto-submit

auto-submit Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/191182, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label.

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 19, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 19, 2026
Merged via the queue into flutter:master with commit 2f0274c Aug 19, 2026
22 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 19, 2026
@bkonyi
bkonyi deleted the crash-dds-http-connection-closed branch August 19, 2026 15:09
@bkonyi bkonyi added the cp: stable cherry pick this pull request to stable release candidate branch label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD cp: stable cherry pick this pull request to stable release candidate branch tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[flutter_tools] Unhandled String exception when VM service connection closes before HTTP header completion (HttpException)

2 participants