Repository navigation
[flutter_tools] Handle HttpException during VM service connection - #191182
Conversation
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
a49af98 to
7c54eae
Compare
There was a problem hiding this comment.
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.
| } on io.SocketException catch (e) { | ||
| await handleError(e); | ||
| } on io.HttpException catch (e) { | ||
| await handleError(e); | ||
| } |
There was a problem hiding this comment.
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
- Suggest simplification and refactoring: Assess whether the code can be made simpler or refactored to enhance readability and maintainability. (link)
There was a problem hiding this comment.
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.
|
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. |
This PR handles
io.HttpExceptionthrown during the VM service connection process influtter_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.connectthrows anio.HttpException. This exception was not caught in_defaultOpenChannelinvmservice.dart, causing the connection loop to terminate abruptly with an unhandled exception and crashing the tool.Fix
io.HttpExceptionto the caught exceptions in_defaultOpenChannel(vmservice.dart), ensuring connection attempts retry with exponential backoff rather than crashing.vmservice_test.dartverifying retry messages and logging behavior whenio.HttpExceptionis encountered during connection.Fixes #191178