[ package:vm_service ] Don't try to send service extension response after service connection disposal

Also prepares for 14.3.1 release.

Fixes https://github.com/flutter/flutter/issues/157296

Change-Id: I623102a54ad7ca4481dd5957a7da65dbc5a2e9b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391500
Commit-Queue: Ben Konyi <bkonyi@google.com>
Auto-Submit: Ben Konyi <bkonyi@google.com>
Reviewed-by: Derek Xu <derekx@google.com>
This commit is contained in:
Ben Konyi
2024-10-22 17:02:02 +00:00
committed by Commit Queue
parent 1d1cbf2837
commit 98ddead31c
5 changed files with 93 additions and 1 deletions
+6
View File
@@ -1,3 +1,9 @@
## 14.3.1
- Fix crash that could occur when trying to send a service extension response
after the service connection had already been disposed of ([flutter/flutter #157296]).
[flutter/flutter #157296]: https://github.com/flutter/flutter/issues/157296
## 14.3.0
- Update to version `4.16` of the spec.
- Add `reloadFailureReason` property to `Event`.
+4
View File
@@ -2023,6 +2023,10 @@ class VmService {
Future _processRequest(Map<String, dynamic> json) async {
final result = await _routeRequest(
json['method'], json['params'] ?? <String, dynamic>{});
if (_disposed) {
// The service has disappeared. Don't try to send the response.
return;
}
result['id'] = json['id'];
result['jsonrpc'] = '2.0';
String message = jsonEncode(result);
+1 -1
View File
@@ -1,5 +1,5 @@
name: vm_service
version: 14.3.0
version: 14.3.1
description: >-
A library to communicate with a service implementing the Dart VM
service protocol.
@@ -0,0 +1,78 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for https://github.com/flutter/flutter/issues/157296
import 'dart:async';
import 'package:vm_service/vm_service.dart';
import 'package:vm_service/vm_service_io.dart';
import 'common/service_test_common.dart';
import 'common/test_helper.dart';
Future<void> testMain() async {}
final tests = <IsolateTest>[
hasStoppedAtExit,
(VmService service, IsolateRef isolateRef) async {
final continueExtensionExecutionCompleter = Completer<void>();
final extensionInvokedCompleter = Completer<void>();
// Setup the service extension.
const String serviceName = 'testService';
service.registerServiceCallback(
serviceName,
(Map<String, dynamic> params) async {
extensionInvokedCompleter.complete();
// Wait for the connection to go down before trying to send the
// response.
await continueExtensionExecutionCompleter.future;
return <String, dynamic>{};
},
);
await service.registerService(serviceName, '');
// Create a secondary service client to invoke the extension.
final client = await vmServiceConnectUri(service.wsUri!);
final serviceExtensionCompleter = Completer<String>();
client.onServiceEvent.listen((e) {
if (e.kind == EventKind.kServiceRegistered) {
print('Service extension registered: ${e.method}');
serviceExtensionCompleter.complete(e.method!);
}
});
await client.streamListen(EventStreams.kService);
// Invoke the extension and wait for the extension to begin executing.
final extensionName = await serviceExtensionCompleter.future;
unawaited(
client
.callServiceExtension(extensionName)
.catchError((_) => Response(), test: (o) => o is RPCError),
);
await extensionInvokedCompleter.future;
// Dispose the connection for the VmService instance with the service
// extension registered to simulate the VM service connection disappearing
// in the middle of handling a service extension request.
await service.dispose();
// Resume the service extension handler. This will cause a
// `Bad state: StreamSink is closed` error if there's a regression.
continueExtensionExecutionCompleter.complete();
// Wait a bit to make sure the exception is thrown before the test
// completes.
await Future.delayed(const Duration(milliseconds: 200));
},
];
void main([args = const <String>[]]) => runIsolateTests(
args,
tests,
'regress_157296_test.dart',
testeeConcurrent: testMain,
pauseOnExit: true,
);
@@ -215,6 +215,10 @@ export 'snapshot_graph.dart' show HeapSnapshotClass,
Future _processRequest(Map<String, dynamic> json) async {
final result = await _routeRequest(json['method'], json['params'] ?? <String, dynamic>{});
if (_disposed) {
// The service has disappeared. Don't try to send the response.
return;
}
result['id'] = json['id'];
result['jsonrpc'] = '2.0';
String message = jsonEncode(result);