Handle a SocketException thrown when sending the browser close command to Chrome (#151197)

https://github.com/flutter/flutter/pull/150645 tries to shut down Chrome by sending a browser close command through a debug protocol.  The webkit_inspection_protocol library used to send the command may throw a SocketException if Chrome has already been shut down.
This commit is contained in:
Jason Simmons
2024-07-03 06:23:20 -07:00
committed by GitHub
parent 84b3f0ab79
commit b373fa2c6e
2 changed files with 33 additions and 2 deletions

View File

@@ -507,8 +507,14 @@ class Chromium {
// Send a command to shut down the browser cleanly.
Duration sigtermDelay = Duration.zero;
if (_hasValidChromeConnection) {
final ChromeTab? tab = await chromeConnection.getTab(
(_) => true, retryFor: const Duration(seconds: 1));
ChromeTab? tab;
try {
tab = await chromeConnection.getTab(
(_) => true, retryFor: const Duration(seconds: 1));
} on SocketException {
// Chrome is not responding to the debug protocol and probably has
// already been closed.
}
if (tab != null) {
final WipConnection wipConnection = await tab.connect();
await wipConnection.sendCommand('Browser.close');