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

Synchronous XHR request through zonejs results in: More tasks executed then were scheduled #377

@thelgevold

Description

@thelgevold

I am logging a bug report:

There seems to be a bug in the bookkeeping of XMLHttpRequest in zone.js.

If I trigger a synchronous XMLHttpRequest when zonejs is loaded on the page I get the following error:
Error: More tasks executed then were scheduled.

The error does not occur if the request is asynchronous.

Here is a simple plunker with a repro: https://plnkr.co/edit/7Cn3JknfDIIHMIdqcuo0?p=preview

I have not looked into this extensively, but the error occurs here:
next is set to -1 which triggers the error condition.

ZoneDelegate.prototype._updateTaskCount = function (type, count) {
                var counts = this._taskCounts;
                var prev = counts[type];
                var next = counts[type] = prev + count;
                if (next < 0) {
                    throw new Error('More tasks executed then were scheduled.');
                }
                if (prev == 0 || next == 0) {
                    var isEmpty = {
                        microTask: counts.microTask > 0,
                        macroTask: counts.macroTask > 0,
                        eventTask: counts.eventTask > 0,
                        change: type
                    };
                    try {
                        this.hasTask(this.zone, isEmpty);
                    }
                    finally {
                        if (this._parentDelegate) {
                            this._parentDelegate._updateTaskCount(type, count);
                        }
                    }
                }
            };

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