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:
parent
1396b8139d
commit
9471e4e216
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user