Unverified Commit 9471e4e2 authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Ensure that VM service extension handlers are run on outer event loop. (#17812)

Fixes https://github.com/flutter/flutter/issues/17597
parent 1396b813
......@@ -363,6 +363,19 @@ abstract class BindingBase {
final String methodName = 'ext.flutter.$name';
developer.registerExtension(methodName, (String method, Map<String, String> parameters) async {
assert(method == methodName);
// VM service extensions are handled as "out of band" messages by the VM,
// which means they are handled at various times, generally ASAP.
// Notably, this includes being handled in the middle of microtask loops.
// While this makes sense for some service extensions (e.g. "dump current
// stack trace", which explicitly doesn't want to wait for a loop to
// complete), Flutter extensions need not be handled with such high
// priority. Further, handling them with such high priority exposes us to
// the possibility that they're handled in the middle of a frame, which
// breaks many assertions. As such, we ensure they we run the callbacks
// on the outer event loop here.
await new Future<void>.delayed(Duration.zero);
dynamic caughtException;
StackTrace caughtStack;
Map<String, dynamic> result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment