javascript - 从谷歌云存储下载文件导致nodejs内存泄漏
问题描述
我正在从我的 nodejs 服务上的谷歌存储下载,我有一个如下所示的实用程序模块:
'use strict';
const BPromise = require('bluebird');
const logger = require('../../setup/logger');
module.exports = () => {
let GCloudStorage = {};
GCloudStorage.getStorage = () => {
return require('@google-cloud/storage')();
};
/**
* @param bucketName
* @param filePath
* @param destination the local disk destination
*/
GCloudStorage.downloadFile = (bucketName, filePath, destination) => {
return new BPromise((resolve, reject) => {
const storage = GCloudStorage.getStorage();
logger.info('Downloading file %s in bucket %s to local path: %s', filePath, bucketName, destination);
const file = storage.bucket(bucketName).file(filePath);
const config = {
destination: destination,
validation: false
};
file.download(config)
.then(() => {
logger.debug('Downloaded gs://%s/%s to %s', bucketName, filePath, destination);
resolve(destination);
})
.catch((err) => {
reject(err);
});
});
};
return GCloudStorage;
};
然后在我的业务代码上,我像这样使用它:
let promises = [];
images.map(image => {
promises.push(storageUtil.downloadFile(config.userFolder, image.image, path.resolve(`./reports/${reportId}/${image.name.replace(/[^a-zA-Z0-9-_\.]/g, '')}`)));
});
return BPromise.all(promises);
当此进程运行时,服务会增加其内存使用量,并且不会在其生命周期内收集它。
我知道这可能是我的代码的 nodejs 问题,但有什么我可以做的吗?
解决方案
推荐阅读
- java - 在不使用数组的情况下获取 N 个输入的最大值
- r - 根据行值从数据框中的不同列中提取数据
- reactjs - React Native 无法读取数据库 Firebase
- python - 使用数组创建循环时出错
- ionic-framework - 我无法使用反应创建离子项目
- python - 密码生成器生成相同的密码
- c++ - 如何在不闪烁的情况下更新控制台并在 C++ 中获取键盘输入
- javascript - what is the name of event?
- javascript - 将图像添加到 html 画布
- java - 当我在我的 android 应用程序中创建图像时拍照时,会在 DCIM / Camera 中生成一个副本