【问题标题】:Node render process gone while downloading files下载文件时节点渲染过程消失
【发布时间】: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


    【解决方案1】:

    好的,看来我在发布此问题时找到了解决方案。反正我还是发一下吧,也许对别人有帮助……

    似乎 google 阻止了即时下载。在下载之间添加 5 秒的超时解决了我的问题。还没有测试超时可以有多低,但也许问题已经通过 settimeout 回调解决了......

    【讨论】:

    • 在此我们可能对正在发生的事情有所了解。有时你只需要让主 JS 线程“喘口气”。通过使用setTimeout,你实际上是在推迟你的函数。也许setTimeout(..., 0) 就足够了,试一试。不用担心0,浏览器会将其限制在最小值(通常为 10 毫秒,但我的信息可能不是最新的)。
    猜你喜欢
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    • 2012-01-23
    • 2014-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多