【发布时间】:2017-12-27 01:05:24
【问题描述】:
我正在编写一个小型 Electron 程序,该程序(当前)能够从 Google Drive 下载多个大文件。有些文件太大而无法扫描,因此它会诱使服务器相信“仍然下载”按钮已被点击。
问题是,在 3、7 或 12 个文件之后,Chrome 开发工具窗口显示“渲染进程已消失”。
3 个文件: - 在尝试连续 3 次下载相同的被阻止文件时打开下载解锁。第 4 个文件崩溃。
7 个文件: - 混合 5 个未阻止的文件和 2 个已阻止的文件并打开下载解锁。第 8 个文件(非阻塞)请求崩溃
12 个文件: - 在下载解锁关闭时下载 9 个未阻止的文件和 3 个被阻止的文件
因此,我得出结论,“解锁”文件占用了 12 个可能的“插槽”中的 3 个。然后,一切(或至少是数字)都会有意义。
通过在同一 url 发送具有相同 cookie 字符和 ?confirm=xxxx 的另一个请求来解除阻止。
请注意,如果我使用具有 100mb 测试文件的另一个文件提供程序,则在 12 个文件之后整个事情不会崩溃。
如果您能指出正确的方向,那将非常有帮助。
这是所用代码的真正简化版本。请注意,缺少许多变量声明和其他内容,但这些部分似乎是有问题的部分:
// downloadmanager.js
function DownloadManager(pack) {
var _this = this;
this.downloadpackages = function (package, data, cb) {
sync.fiber(function () {
...
Object.keys(ht_distinct_urls).forEach(function (url) {
localfile = sync.await(_this.download(remotefile, sync.defer()));
console.log("Downloaded:" + localfile);
});
});
}
this.dl = function (remotefile, cb) {
request(request_options, (err, response, body) => {
// cb() in this location makes it crash at the 13th file
cb(null, "");
});
// cb() in this location doesnt make it crash (but also not download anything)
//cb(null, "");
}
this.download = function (remotefile, cb) {
// Try to download
_this.dl(remotefile, function (err, data) {
if (data.downloaded) { // It worked
cb(err, data);
} else if (data.unblocked) { // It was able to get a code to unblock it
_this.dl(data, cb); // Try again with the new cookie and the code
} else {
// Fck it, just return the data anyway for debugging
cb(err, data);
}
});
};
}
// renderer.js
sync.fiber(function () {
var pack = getPackage();
var dm = new DownloadManager(pack);
var download_result = sync.await(dm.downloadpackages(pack, ht_distinct_urls, sync.defer()));
console.log(download_result);
});
【问题讨论】:
标签: javascript node.js request electron