Skip to content

Engine's method of invoking callbacks in the same zone they were set from is unsound #101448

@dnfield

Description

@dnfield

See flutter/engine#32078 (comment)

You should register the callback in the zone, using

  var currentZone = Zone.current;
  _onErrorZone = currentZone;
  _onError = (callback == null) ?  null : 
       currentZone.registerBinaryCallback(callback);
Notice that that makes the stored function not necessarily be the same as the argument to the setter.
It might be a case where there shouldn't be a getter.

(Why is there a getter? What is the expected use?)
If you don't like having a setter without a getter, you can use the format used by StreamSubscription with .onData(callback) instead of .onData = callback.

Consider not storing a zone if here is no callback. But better yet, use bindBinaryCallback instead to store the zone inside the callback instead of on the side:

  _onError = callback == null ? null : 
        Zone.current.bindBinaryCallback(callback);

This comment was for adding a new callback, but the existing ones follow this pattern. We should go through and clean them up in one fell swoop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listengineflutter/engine related. See also e: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions