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

Fixes https://github.com/flutter/flutter/issues/17597
This commit is contained in:
Todd Volkert 2018-05-22 11:55:46 -07:00 committed by GitHub
parent 1396b8139d
commit 9471e4e216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;