diff --git a/pkg/dds/lib/src/isolate_manager.dart b/pkg/dds/lib/src/isolate_manager.dart index 6ebfafaa94a..ddee5f959a8 100644 --- a/pkg/dds/lib/src/isolate_manager.dart +++ b/pkg/dds/lib/src/isolate_manager.dart @@ -346,13 +346,17 @@ class IsolateManager { final combinedBytes = base64Decode(timelineResult['trace']).toList(); for (final isolateId in isolates.keys) { - final samplesResult = - await dds.vmServiceClient.sendRequest('getPerfettoCpuSamples', { - 'isolateId': isolateId, - 'timeOriginMicros': timeOriginMicros, - 'timeExtentMicros': timeExtentMicros - }); - combinedBytes.addAll(base64Decode(samplesResult['samples'])); + try { + final samplesResult = + await dds.vmServiceClient.sendRequest('getPerfettoCpuSamples', { + 'isolateId': isolateId, + 'timeOriginMicros': timeOriginMicros, + 'timeExtentMicros': timeExtentMicros + }); + combinedBytes.addAll(base64Decode(samplesResult['samples'])); + } on json_rpc.RpcException { + // The isolate may not yet be runnable. + } } timelineResult['trace'] = base64Encode(combinedBytes); return timelineResult; diff --git a/pkg/dds/test/dap_handler_test.dart b/pkg/dds/test/dap_handler_test.dart index b61235ffb31..f2a8d3684c9 100644 --- a/pkg/dds/test/dap_handler_test.dart +++ b/pkg/dds/test/dap_handler_test.dart @@ -116,8 +116,18 @@ void main() { ); service = await vmServiceConnectUri(dds!.wsUri!.toString()); - final isolate = (await service.getVM()).isolates!.first; - final isolateId = isolate.id!; + final isolateRef = (await service.getVM()).isolates!.first; + final isolateId = isolateRef.id!; + + // Wait for the isolate to become runnable as `evaluateInFrame` requires + // the isolate to be runnable. + Isolate? isolate; + do { + if (isolate != null) { + await Future.delayed(const Duration(milliseconds: 50)); + } + isolate = await service.getIsolate(isolateId); + } while (!isolate.runnable!); // Get the variable for 'myInstance'. final originalInstanceRef = (await service.evaluateInFrame(