上传文件,间隔2、3天报122错误

开发语言:nodejs
问题:上传文件,间隔2、3天保122错误,然后就再也上传不了了。
现象:正常情况下,上传文件正确,过2、3天上传文件部分,就出现122错误,重启一下实例又可以上传。我觉得要么都上传不了,要么都上传的了,不能重启下实例就可以上传了吧,难道是因为资源不够了?麻烦老师们给一个解决方案的参考。

错误提示:{"errno":-122,"code":"Unknown system error -122","syscall":"open","path":"/tmp/Fds_8mw1a7Fr4ZxF_oRsxRmg.jpg"}

错误截图:

云引擎的磁盘只能用作临时存储,也有 1 G 的限制。从您描述的现象来看,可能是上传的文件总和超过了 1 G 的大小,所以无法上传。重启实例后临时文件清空了,就可以上传了。

这个应该不是临时文件的问题,我们上传的时候不是传入到/home/leanengine 或 /tmp的,我们升级了资源,暂时先观察一下

可以描述下你们的项目是通过什么方式实现文件上传,或者贴下相关代码片段吗?

router.post("/upload", function (req, res) {
    var form = new multiparty.Form();
    form.parse(req, function (err, fields, files) {       
        if(err){
            console.error("上传文件失败:",JSON.stringify(err));  
            /*根据打印的日志,在此步骤就出错了,过几天就报如下错误:
            {"errno":-122,"code":"Unknown system error -122","syscall":"open","path":"/tmp/Fds_8mw1a7Fr4ZxF_oRsxRmg.jpg"}*/
        }

        if (files == null) {
            console.error("没有得到文件:",JSON.stringify(err)); 
            res.send({ code: 502, msg: "请选择要上传文件" });
        }
        else {
            comFun.saveFileThen(files, function (fileInfos) {
                if (fileInfos) {
                    var returnInfos = fileInfos.map((fileInfo, index) => {
                        return {
                            url: fileInfo.url,
                            fileId: fileInfo.id,
                            fileName: fileInfo.name
                        };
                    });
                    res.send({
                        code: 200,
                        url: returnInfos[0].url,
                        fileId: returnInfos[0].fileId,
                        fileName: returnInfos[0].fileName, 
                        files: returnInfos,
                        msg: 'ok',
                        error: 0
                    });
                } else { 
                    var error = new AV.Error();
                    error.code = 502;
                    error.message = "上传失败!";
                    error.error = 1;
                    res.send(error);
                }
            })
        }
    });
});

//上传到leanCloud
function saveFileThen(myFiles, callbackFun) {
    if (myFiles == null) {
        callbackFun();
        return;
    } 
    var attachmentFiles = myFiles.file || myFiles.attachment || myFiles.imgFile;  
    var ps = [];
    attachmentFiles.forEach((attachmentFile, index) => {
        ps[index] = new Promise(function (resolve, reject) {
            if (attachmentFile && attachmentFile.size !== 0 && attachmentFile.originalFilename !== '') {
                fs.readFile(attachmentFile.path, function (err, data) {
                    if (err) {
                        console.error("读取文件失败:"+err.message)
                        reject({msg: err.message, url: () => "", name:attachmentFile.originalFilename});
                        return;
                    }
                    var theFile = new AV.File(attachmentFile.originalFilename, data);
                    theFile.save().then(function (theFile) { 
                        resolve({
                            url: theFile.url(),
                            name: attachmentFile.originalFilename,
                            id: theFile.id
                        });
                    }, function (err) {
                        console.error("上传到LeanCloud失败:"+ JSON.stringify(err))
                        resolve({msg: err.message, url: () => "", name:attachmentFile.originalFilename });
                    });
                });
            } else {
                reject({msg: "no_file_fount", url: () => ""});
            }
        });
    });

    Promise.all(ps).then(function (results) {
        callbackFun(results);
    },function(err){
        console.error("Promise.all,上传到LeanCloud失败:"+ JSON.stringify(err))
        resolve()
    }); 
}

从目前的报错信息上看不出什么头绪(除了这个报错很可能跟 IO 相关)。看起来您用了 multiparty 这个包,可以看下它的文档或者到它的社区去问下,看看 parse 环节报错时能不能打印出更详细的日志。