Skip to content

Script70 "Access Denied" or "Permission Denied" when animating embed'ed svg elements #2189

Closed

Description

@dwt
  • The bug manifests itself as 'Script70' Error (error message "Access Denied" or "Permission Denied")
  • If an SVG element is <embedd src=some.svg> on a page and is then removed while an animation is still running in it - an exception is sometimes thrown from d3.timer.tick() or d3.timer.stop(). To be more specific d3.timer stores state on a DOM node in the transition attribute and then tries to delete node.__transition__ it in d3.timer.stop(). That will fail if the SVG element cannot be accessed (attribute access or assignments fail with an error). If d3.timer.tick() calls a function that does the animation (this could also be a custom attrTween) and it throws the timer continuation is stopped.
  • This is non recoverable by the application and will stop all concurrently runnning animations and will prevent all animations scheduled after that point!
  • This is also not reliably preventable by the application as there is no way to synchronously stop an animation. selection.interrupt().transition() and d3.timer.flush() all are asynchronous and thus the race condition between stopping the animation and IE killing of the SVG element remains.
  • We suspect that the IE js garbage collector is to blame for this, as the problem happens after varying intervals and can be triggered more easily if there is more activity in the DOM.

Possible solutions / workarounds:

  • Keeping a reference to the embed DOM element seems to keep it alive - keeping a d3.selection of the SVG element (path, group, etc) inside it doesn't. This could mean that changing the way animations remember the elements they're working on could prevent this error.
  • Catching and possibly discariding exceptions thrown from the handlers called by d3.timer.tick() and d3.timer.stop() so one erroneous SVG element doesn't kill all other d3 animations.
  • Listen to DOM-removal events and internally and synchronously kill timers on the removed elements.
  • Providing a solution to synchronously stop an animation. This could allow an app using d3 to work around this problem by stopping the animation before it removes the containing DOM element.

We would prefer a solution that doesn't require the d3 using app to include ie10/11 workarounds.

That being said, we think it would be very beneficial if we could force d3 to synchronously get rid of timeouts/ transitions/ animations/ ... on dom nodes. This would have helped us tremendously to track down/ work around this problem and would help d3 using applications to more easily work around similar issues when they are found in the future, until a real solution / fix is implemented in d3.

See this blocks gist for a demonstration/ reduction of this problem.

Activity

  1. rbu commented on Jan 13, 2015

    @rbu
    Contributor
  2. mbostock commented on Jan 13, 2015

    @mbostock
    Member

    d3.timer.flush is synchronous, not asynchronous.

  3. mbostock commented on Oct 21, 2015

    @mbostock
    Member
  4. added
    bug
    on Oct 21, 2015
  5. mbostock commented on Oct 22, 2015

    @mbostock
    Member

    This is also not reliably preventable by the application as there is no way to synchronously stop an animation.

    If you know that there are no inactive transitions scheduled, you can synchronously stop any active transition by saying:

    selection.interrupt();
    d3.timer.flush();

    (If you want a big hammer, replace selection with d3.select("*").)

    This will delete node.__transition__ on any selected node before timer.flush returns, which should avoid the error.

    However, this won’t work if you have an inactive transition scheduled, because selection.interrupt only interrupts the active transition and does not cancel scheduled transitions. You might think to try:

    selection.interrupt().transition().duration(0);
    d3.timer.flush();

    But this doesn’t quite work, either, because pre-empted transitions don’t clean themselves up until they start (whereupon they notice that lock.active > id and immediately stop). So the deletion of node.__transition__ still doesn’t happen until the pre-empted transition starts.

    Probably what we need here is a way for pre-empted transitions to be garbage collected immediately when the pre-empting transition starts. This way, the above code would do what we want. (And so would a selection.cancel method, or an improved selection.interrupt, as discussed in d3/d3-transition#9.) But in order to do that, I think we need a way to cancel a scheduled timer, and currently the only way to terminate a timer is to invoke its callback and have it return true. So I’ve filed d3/d3-timer#5.

  6. added this to the 4.0 milestone on Oct 22, 2015
  7. modified the milestones: 3.5.7, 4.0 on Oct 25, 2015
  8. mbostock commented on Oct 25, 2015

    @mbostock
    Member

    In 3.5.7, the provided workaround will work as expected because cancelled transitions are now cleaned up synchronously:

    selection.interrupt().transition().duration(0);
    d3.timer.flush();

    In 4.0, we will change the behavior of selection.interrupt() to cancel any scheduled transitions in addition to interrupting the active transition, which I think is a more sensible default behavior. So in that case, you’d be able to say selection.interrupt() and be done. See #2600 for the fix.

  9. mbostock commented on Oct 25, 2015

    @mbostock
    Member

    Fixed in #2600, staged in #2591 for 3.5.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions