Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

"More tasks executed then were scheduled" exception thrown #287

Closed
mdekrey opened this issue Mar 20, 2016 · 68 comments
Closed

"More tasks executed then were scheduled" exception thrown #287

mdekrey opened this issue Mar 20, 2016 · 68 comments
Assignees

Comments

@mdekrey
Copy link

mdekrey commented Mar 20, 2016

First off, I'll admit to not knowing whether this is an Angular2 or Zone.js issue. Sorry if I'm putting it in the wrong Issues list!

When loading the Google Maps API asynchronously, setTimeout and clearTimeout appear to be called which causes the error More tasks executed then were scheduled.

When I load it before the zone.js library, I am able to get further in the process. However, callbacks threw similar errors (eventually) without further instrumentation. (I'm not sure if this is expected, but I suspect it is. I figured I'd mention it just in case.)

I have not been able to resolve, however, that the error occurs again if I leave the window and return upon moving my mouse over the map again. This event appears to be wholly internal to Google Maps, and I can't capture it. Unfortunately, due to the debugger; line in the code, I'm unable to just ignore it for the time being without altering the codebase.

I'm using Angular 2.0.0-beta.11 and zone.js 0.6.4.

@robwormald
Copy link
Contributor

Could you post a reproduction in a plunker? This wouldn't wholly surprise me but I can't reproduce it.

@fxck
Copy link

fxck commented Mar 22, 2016

@robwormald happens when using this lib https://github.com/stabzs/Angular2-Toaster as well, after the notification timeouts and is about to disappear

@born2net
Copy link

+1 seeing same issues
Another plunkr for reference: http://plnkr.co/edit/coyaquV0zuwwVGLGAGUE?p=preview
drag the sliders to reproduce...

@born2net
Copy link

I will add that this seems to have started in 0.10...

@born2net
Copy link

FYI disabled snippet is a workaround until issue is fixed in zone.ts

line: 763 zone.ts
if (next < 0) {
        debugger;
        throw new Error('More tasks executed then were scheduled.');
      }

@rvalimaki
Copy link

Happens with my app as well, all the time. I'm not using anything related to Google Maps, so I guess it's completely irrelevant to the subject. Probably the title should be altered to better match the subject.

@born2net: What do you mean by "disabled snippet"? I there any workaround over this issue without touching Zone.js?

I'm not sure if it's related, but I'm also receiving exceptions about Task cancellation:
"EXCEPTION: Error: Task does not support cancellation, or is already canceled.

at ZoneDelegate.cancelTask (eval at (http://localhost:8080/polyfills.bundle.js:1106:2), :218:23)
at Zone.cancelTask (eval at (http://localhost:8080/polyfills.bundle.js:1106:2), :128:44)
at eval (eval at (http://localhost:8080/polyfills.bundle.js:101:2), :88:23)
at clearTimeout (eval at createNamedFn (eval at (http://localhost:8080/polyfills.bundle.js:372:2)), :3:39)
...
"

@born2net
Copy link

yes I removed the above code from the zone file so it does not error... for now..

@DominicBoettger
Copy link

Installed angular beta9. Same issue....

@born2net
Copy link

still same issue in 0.12

More tasks executed then were scheduled.

@rvalimaki
Copy link

@DominicBoettger

did you just downgrade Angular version, or the Zone.js version too?

I'm pretty sure I didn't have any problems with our rather large application in beta.9 (apart from the obvious: minifying broken etc., but those are easy to overcome).

EDIT:
Confirmed with several times. It doesn't occur when Angular version is beta .9 and Zone.js 0.5.15, but occurs with Angular beta.11 (and reportedly 0.10 and 0.12 too) with Zone.js 0.6.4 all the time with our product.

I'm using ~latest version of Angular2-webpack-starter, and I needed to downgrade only Angular & Zone versions as well as older polyfills.ts accordingly to get rid of all errors.

EDIT2: This issue is still completely unrelated to usage of Google Maps Javascript API, as also proved by the plunker above. Though it's possible that this is somehow related to any use of an external library, such as jQuery, as is the case with above plunker and my own code.

@fxck
Copy link

fxck commented Mar 24, 2016

no luck with b12 and 0.6.6, it's still throwing the error, the only difference is that it's not triggering debugger

@born2net
Copy link

this is a big showstopper for me...
I can't release ng 0.12 Kitchen sink: http://ng2.javascriptninja.io
due to this bug...

ng team, PLEASE remove the Throw Exceptions in zone.js

Regards,

Sean

@CaptainCodeman
Copy link

I am getting this on beta-12 - it happens when using angular2-moment, specifically the timeago pipe but not consistently. It "feels" like it's when things are rendered and removed a few times but I haven't tracked it down yet. Bizarrely, turning on source-maps to diagnose the problem seemed to make it happen less (possibly random chance or my imagination).

@ericmartinezr
Copy link

@mdekrey could you edit the title of the issue to make it easier to find please? Something like More tasks executed then were scheduled.

By the way this is being tracked here also angular/angular#7721

@mdekrey mdekrey changed the title Various conflicts with Google Maps Javascript API More tasks executed then were scheduled Mar 26, 2016
@mdekrey mdekrey changed the title More tasks executed then were scheduled "More tasks executed then were scheduled" exception thrown Mar 26, 2016
@caJaeger
Copy link

@CaptainCodeman I am also experiencing this with my timeAgo pipe, only became an issue when upgrading to beta12.

@msklvsk
Copy link

msklvsk commented Mar 31, 2016

same here, beta.13, latest everything

@rvalimaki
Copy link

Latest zone.js (0.6.8?) with ng2 beta.13 fixed this for me. I think that the main problem is in zone.js version 0.6.7.

@rvalimaki
Copy link

Look at the other (duplicate) issue for instructions how to setup Angular2 beta.13 with Zone.js version 0.6.8:

angular/angular#7721

bionicvapourboy added a commit to bionicvapourboy/zone.js that referenced this issue Apr 6, 2016
@Tragetaschen
Copy link

I'm still seeing this in 0.6.9. I've got a component that does TimerWrapper.setInterval() in the constructor and TimerWrapper.clearInterval() in ngOnDestroy. The latter throws the exception when I navigate away and the component is destroyed.

Error: More tasks executed then were scheduled.
   at ZoneDelegate.prototype._updateTaskCount (http://localhost:4146/vendor-dev.js:83719:19)
   at ZoneDelegate.prototype.cancelTask (http://localhost:4146/vendor-dev.js:83707:19)
   at Zone.prototype.cancelTask (http://localhost:4146/vendor-dev.js:83610:15)
   at Anonymous function (http://localhost:4146/vendor-dev.js:83466:19)
   at clearInterval (Function code:1:33)
   at TimerWrapper.clearInterval (http://localhost:4146/vendor-dev.js:11912:51)
   at CurrentTimeComponent.prototype.ngOnDestroy (http://localhost:4146/F500-Web-dev.js:2162:10)
   at ChangeDetector_UiStatusbarComponent_0.prototype.dehydrateDirectives (Function code:442:1)
   at AbstractChangeDetector.prototype.dehydrate (http://localhost:4146/vendor-dev.js:11611:10)
   at AbstractChangeDetector.prototype.destroyRecursive (http://localhost:4146/vendor-dev.js:11624:10)

@ericmartinezr
Copy link

@Tragetaschen first you need a reproduction of your issue, and second you shouldn't be using angular2's internal api.

@Tragetaschen
Copy link

Yeah, I have replaced those by just setInterval. I think there was a time when some angular2 samples showed using TimerWrapper…
I have removed that and am just following something similar to this and don't runt into it anymore

@Tragetaschen
Copy link

I have seen this again today with the SignalR client, but I cannot reproduce this.

In my component in ngOnDestroy, I call connection.stop() which in turn calls clearInterval

The call stack looks exactly like the one I already posted (with a different component), but it doesn't happen in any reliable way. Nothing I tried so far was able to trigger it, including doing the same steps in the browser again (and again, and again) with my application.

@kanchansingh1123
Copy link

Use Angular to "2.0.0-beta.14" with zone "0.6.10" in my package.json and I run npm install.

It fix the issue.

@mikebm
Copy link

mikebm commented Apr 11, 2016

@kanchansingh1123 Odd, I am using "2.0.0-beta.14" with zone "0.6.10" and the issue still persists with angular2-toaster project.

@kanchansingh1123
Copy link

I am using angular2-webpack-starter

and it works fine.

@mikebm
Copy link

mikebm commented Apr 13, 2016

@fxck Figured out why angular2-toaster is causing this exception. If you call clearTimeout in the setTimeout callback, it will trigger this exception. This is exactly what removeToast() is doing.

@kemsky
Copy link

kemsky commented Sep 12, 2016

Press test and wait for a few seconds: plunker

It seems that there are few bugs that lead to the same exception, i would suggest to create debug version of zone to trace this bugs.

@mhevery
Copy link
Contributor

mhevery commented Sep 13, 2016

@kemsky Perfect, and thanks for a repro.

raskchanky added a commit to habitat-sh/habitat that referenced this issue Nov 23, 2016
See angular/zone.js#287 for more details,
including the solution I used here.

Signed-off-by: Josh Black <raskchanky@gmail.com>
raskchanky added a commit to habitat-sh/habitat that referenced this issue Nov 28, 2016
See angular/zone.js#287 for more details,
including the solution I used here.

Signed-off-by: Josh Black <raskchanky@gmail.com>
raskchanky added a commit to habitat-sh/habitat that referenced this issue Nov 28, 2016
See angular/zone.js#287 for more details,
including the solution I used here.

Signed-off-by: Josh Black <raskchanky@gmail.com>
raskchanky added a commit to habitat-sh/habitat that referenced this issue Nov 29, 2016
See angular/zone.js#287 for more details,
including the solution I used here.

Signed-off-by: Josh Black <raskchanky@gmail.com>
mlmassey pushed a commit to mlmassey/zone.js that referenced this issue Dec 6, 2016
Remove exception being thrown
Fixes angular#287
@mlmassey
Copy link

mlmassey commented Dec 6, 2016

@mhevery I ran into this same issue while working with Mapbox-gl integrated into our app. Unfortunately, when the exception gets thrown, the app becomes unusable. I tracked this down to promise chains not resolving after the exception is thrown. I followed the recommendation of removing the line that throws the exception, although I don't feel comfortable about it, but it does remove the problem.

I'm happy to help you debug further, but I would like to know why an exception is thrown here. Obviously it's not a condition expected to be hit, but I can see that the other parts of the zone code that use the _updateTaskCount() function are using it outside of the try blocks (and calling it in finally). It would be better to gracefully handle this condition, or at least provide a recommendation on what should be done to catch this exception and do something about it in the app.

@JiaLiPassion
Copy link
Collaborator

JiaLiPassion commented Dec 6, 2016

For this plunker provided by @kemsky, the error can be described as the following test case

    Zone.current.fork({name:'test'}).run(function() {
      var req = new XMLHttpRequest();
      req.open('get', '/', true);
      req.send();
      req.onloadend = function() {
        req.open('get', '/', true);
        req.send();
      }

readystatechange eventhandler was added multiple times, https://github.com/angular/zone.js/blob/master/lib/browser/browser.ts#L66, I made a PR #527 to fix it.

@mlmassey
Copy link

mlmassey commented Dec 7, 2016

@JiaLiPassion I confirmed your change fixes the issue that I see. I'll be eager to see your fix merged in so I can use it.
Note, I still think it's not wise to have the exception in the code unless there is some proper way to properly handle it. Is it possible to remove this and gracefully handle the condition?

@JiaLiPassion
Copy link
Collaborator

@mlmassey thank you for confirm the issue, I think the error code means it should never be executed, if such kind of error occurs, something must be wrong and not recoverable (running task is much more than scheduled task). So I think we should make sure that all bugs are fixed so the code will never run.

@aleksey-shishkevich
Copy link

same error in 0.7.2. like @garethdn I am using Marketo tracking plugin.
my question is the workaround

/*
            if (next < 0) {
                throw new Error('More tasks executed then were scheduled.');
            }
*/
            if (prev == 0 || next <= 0) {

safe enough?

@JiaLiPassion
Copy link
Collaborator

@alsh76 no, I don't think comment out the error thrown code is safe, maybe the update count part's behavior will be ok with such workaround, but the real reason cause next <0 will get other problem. for example the xmlhttprequest addEventListener was triggered multipletimes may cause same handler logic run multipletimes.

So in my understanding the error part is really a mechanism to avoid further bigger error.

@iFadey
Copy link

iFadey commented Dec 16, 2016

@alsh76 Version 0.7.2 doesn't have that fix.

https://github.com/angular/zone.js/blob/v0.7.2/lib/zone.ts#L869

@aleksey-shishkevich
Copy link

So what would be the best workaround for the issue? I do not want to modify
http://munchkin.marketo.net/151/munchkin.js

@mhevery
Copy link
Contributor

mhevery commented Dec 17, 2016

Could someone create a plunker which demonstrates the issue. None of the plunkers listed reproduce the issue for me.

@JiaLiPassion
Copy link
Collaborator

JiaLiPassion commented Dec 17, 2016

@mhevery here is the plunker
case1, multiple event handler case
case2, invalide url case
And please review my PR for the fix of those issues.
pr

@aleksey-shishkevich
Copy link

This fix did not resolve the conflict with Marketo tracking plugin. same error

@JiaLiPassion
Copy link
Collaborator

@alsh76
could you give me a simple reproduce step?

@RicardoVaranda
Copy link

RicardoVaranda commented Dec 29, 2016

@JiaLiPassion
@mhevery
@alsh76

I'm getting the exact same error once I try to use Tealium which is a tag management system and marketo is actually one of the dependencies on it:

https://plnkr.co/edit/seTYkcMqHNlTu9d86AOy?p=preview

Stack:

zone.js@0.7.4?main=browser:682 
Uncaught Error: More tasks executed then were scheduled.
    at ZoneDelegate._updateTaskCount (https://unpkg.com/zone.js@0.7.4?main=browser:310:23) [<root>]
    at ZoneDelegate.invokeTask (https://unpkg.com/zone.js@0.7.4?main=browser:280:26) [<root>]
    at Zone.runTask (https://unpkg.com/zone.js@0.7.4?main=browser:151:47) [<root> => <root>]
    at ZoneTask.invoke (https://unpkg.com/zone.js@0.7.4?main=browser:345:33) [<root>]
    at data.args.(anonymous function) (https://unpkg.com/zone.js@0.7.4?main=browser:1224:25) [<root>]

@JiaLiPassion
Copy link
Collaborator

JiaLiPassion commented Dec 29, 2016

@RicardoVaranda , Thank you for your demo, I will debug into it.
I just find out the problem, and I will commit a PR to it.

raskchanky added a commit to habitat-sh/builder that referenced this issue Jan 18, 2018
See angular/zone.js#287 for more details,
including the solution I used here.

Signed-off-by: Josh Black <raskchanky@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests