Skip to content

clearInterval crashes zones in beta.11 #7666

Closed

Description

@wardbell

[x] bug report

Either of these will crash zones

var timerId = 42; // anything that isn't actually a handle
clearInterval(timerId);
// Error: cannot read property 'cancelTask' of undefined

and try this

var timerId = setInterval(()=>{},1000);
clearInterval(timerId); // clears the first timer
clearInterval(timerId); // called twice ... boom!
// Uncaught Error: Task does not support cancellation, or is already canceled.

clearInterval is supposed to be safe in both cases`. It worked in beta.9

Here it is in a plunker:
http://plnkr.co/edit/nyQIKU4JzTlwp5eOG7Qo?p=preview

Discovered while testing the docs "Cookbook Component Communication" sample. Here it is in the context of that cutdown sample:
http://plnkr.co/edit/pYlQdKk6qLOGhQwSreoG?p=preview

Activity

  1. ericmartinezr commented on Mar 19, 2016

    @ericmartinezr
    Contributor

    @wardbell the second one is this one angular/zone.js#283, the first one I don't know...

  2. wardbell commented on Mar 19, 2016

    @wardbell
    ContributorAuthor

    It does seem related @ericmartinezr . But the first one might be different

  3. NathanWalker commented on Mar 19, 2016

    @NathanWalker
    Contributor

    Sounds like the error I'm seeing with beta.11 is related; coming from angular2-polyfills:

    Uncaught TypeError: Cannot read property 'cancelTask' of undefined(anonymous function) @ angular2-polyfills.js?1458368121888:142
    clearTimeout @ VM740:3
    subs.push.destroy @ browser-sync-client.2.10.1.js:1
    Manager.cleanup @ browser-sync-client.2.10.1.js:1
    

    And:

    Uncaught TypeError: Cannot read property 'zone' of undefined(anonymous function) @ angular2-polyfills.js?1458368121888:142
    clearTimeout @ VM740:3
    Socket.onClose @ browser-sync-client.2.10.1.js:1
    

    This appears to be called twice on bootstrap from angular2-polyfills.js. First time zone is defined. Second time it's not:

    var clearNative = utils_1.patchMethod(window, cancelName, function () { return function (self, args) {
       var task = args[0];
       task.zone.cancelTask(task);  <-- zone undefined 2nd time
    }; });
    
  4. johnwheeler commented on Mar 19, 2016

    @johnwheeler

    @NathanWalker

    I had to do this to make the errors go away - mind you - I have no idea of the side-effects or what any of this is doing...

    var clearNative = utils_1.patchMethod(window, cancelName, function () { return function (self, args) {
        var task = args[0];
        if (task) { // <--- added guard
            task.zone.cancelTask(task);
        }
    }; });
    

    FWIW, I tried the temp workaround from @todoubaba here

    #7671 (comment)

    and it did not solve the browsersync errors

  5. PatrickJS commented on Mar 20, 2016

    @PatrickJS
    Contributor

    if you build from source you can apply this workaround
    PatrickJS/angular-webpack-starter@1661e4c

  6. mhevery commented on Mar 21, 2016

    @mhevery
    Contributor
  7. char0n commented on Mar 22, 2016

    @char0n

    Hi,

    I am using angular 2.0.0-beta.11 and zone.js 0.6.5 in hybrid application along with angular 1.5.2. I am still experiencing the issue with unhandled exception: EXCEPTION: Error: Task does not support cancellation, or is already canceled.

    I can create plunker if necessary. Can anybody confirm ?

  8. kookster commented on Mar 24, 2016

    @kookster

    I'm seeing the same thing in angular 2.0.0-beta.11 with zone.js 0.6.6

    Seems to be two issues, I am seeing times when it is trying to call clearNative with args containing an integer like 13 or 14 rather than a ZoneTask. That happens a few times as my app starts up.

    More frequently after that I see clearNative called twice on the same ZoneTask, where the 2nd time is doomed to fail as the cancelFn has been set to null in the first call. Haven't chased down where this is happening, but this change to angular2-polyfills.js prevents the errors:

            var clearNative = utils_1.patchMethod(window, cancelName, function() {
              return function(self, args) {
                var task = args[0];
                if (task && task.cancelFn) { // THIS CONDITION
                  task.zone.cancelTask(task);
                }
              };
            });
    
  9. kookster commented on Mar 24, 2016

    @kookster

    Actually, looks like this function has already been fixed in a similar way in zone.js, but angular2-polyfills.js is not updated with this yet:

    https://github.com/angular/zone.js/blob/master/lib/browser/browser.ts#L86-L97

    So basically we need angular2-polyfills.js updated with the latest zone.js.

  10. kookster commented on Mar 24, 2016

    @kookster

    I see beta 12 is out with this fix, this should be closed

  11. pkozlowski-opensource commented on Mar 24, 2016

    @pkozlowski-opensource
    Member

    Thnx @kookster !

  12. char0n commented on Mar 25, 2016

    @char0n

    Nice, I can confirm that these errors are gone on hybrid angular1/2 application with angular2 v2.0.0-beta.12 and zone.js v 0.6.6

    Thanks a lot for fixing this

  13. bennadel commented on Apr 10, 2016

    @bennadel

    For what's it's worth, I also just happened across this in Beta 11:

    angular2-polyfills.js:460 Unhandled Promise rejection: EXCEPTION: TypeError: Cannot read property 'zone' of null

    ... when trying to use clearTimeout(). It seems to be fixed in Beta 14. Thanks!

  14. char0n commented on Apr 10, 2016

    @char0n

    Yes I can still reproduce also on hybrid angular1/2 application.

    angular=1.5.3
    angular2=2.0.0-beta.13
    zone.js=0.6.9

    app.js:129453 Error: [$rootScope:inprog] $digest already in progress
    http://errors.angularjs.org/1.5.3/$rootScope/inprog?p0=%24digest
        at app.js:116097
        at beginPhase (app.js:133412)
        at Scope.$apply (app.js:133152)
        at app.js:115493
        at ZoneDelegate.invoke (app.js:108306)
        at Zone.run (app.js:108201)
        at NgZoneImpl.runOuter (app.js:59983)
        at NgZone.runOutsideAngular (app.js:43180)
        at Object.next (app.js:115493)
        at SafeSubscriber.schedulerFn [as _next] (app.js:5753)
  15. mhevery commented on Apr 10, 2016

    @mhevery
    Contributor

    @char0n Please file a separate issue, with a plunker reproduction.

  16. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  17. locked and limited conversation to collaborators on Sep 8, 2019
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions