铬的xhr请求太多了

时间:2013-05-27 14:45:02

标签: google-chrome xmlhttprequest chromium

我有一个紧凑的循环,通过xhr2获取PNG文件。在FF和IE10中工作正常。在Chrome浏览器中,当我列出的文件大约达到5,500时,我开始收到xhr错误。我喜欢异步接口,因为我将这些请求与本地indexedDB存储请求交错。

下面的代码(我使用xhr2lib进行提取,使用PouchDB进行IndexedDB API)。

我知道XHR2是失败的,因为当它工作时,在Chrome中,所有XHR2调用都在SaveDB()调用之前被处理。当它失败时,我从未收到保存电话。

function getBlobs(fileList) {
    console.log("starting to fetch blobs");
    $.each(fileList, function (i, val) {
        var path = baseURL + val.id + "." + imageType;
        $xhr.ajax({
            url: path,
            dataType: "blob",
            success: function (data) { saveBlob(data, val.size, val.id); }
        });
    });
}

function saveBlob(blob, length, id) {
    if (blob.size != length) {
        console.error("Blob Length found: " + blob.size + " expected: " + length);
    }
    putBlob(blob, id);
    ++fetchCnt;
    if (fetchCnt == manifest.files.length) {
        setTimeout(fetchComplete, 0);
    }
}

function fetchComplete() {
    var startTime = vm.get("startTime");
    var elapsed = new Date() - startTime;
    var fetchTime = ms2Time(elapsed);
    vm.set("fetchTime", fetchTime);
}

function putBlob(blob, id) {
    var cnt;
    var type = blob.type;
    DB.putAttachment(id + "/pic", blob, type, function (err, response) {
        if (err) {
            console.error("Could store blob: error: " + err.error + " reason: " + err.reason + " status: " + err.status);
        } else {
            console.log("saved: ", response.id + " rev: " + response.rev);
            cnt = vm.get("blobCount");
            vm.set("blobCount", ++cnt);
            if (cnt == manifest.files.length) {
                setTimeout(storeComplete, 0);
            }
        }
    });
}

1 个答案:

答案 0 :(得分:0)

铬人们承认这是他们应该解决的问题:https://code.google.com/p/chromium/issues/detail?id=244910,但与此同时我使用jquery defer / resolve实现了限制以保持线程数低。