简体   繁体   English

fs.writeFile 后 Google 云功能崩溃

[英]Google cloud function crashing after fs.writeFile

I have a bit of a strange bug.我有一个奇怪的错误。 I am using firebase's cloud functions for some data processing.我正在使用 firebase 的云功能进行一些数据处理。 Within the function, I need to (a) write a CSV to the tmp/ folder on the disk, (b) upload this file to google cloud storage.在该函数中,我需要 (a) 将 CSV 写入磁盘上的 tmp/ 文件夹,(b) 将此文件上传到谷歌云存储。

I am using fs.writeFile to write to disk.我正在使用 fs.writeFile 写入磁盘。 This works fine--the data is correctly written to the tmp folder.这工作正常 - 数据正确写入 tmp 文件夹。 BUT, the whole function crashes if it doesnt immediately resolve.但是,如果不立即解决,整个函数就会崩溃。 So if there's a next step in function (like waiting for the upload to finish with google cloud storage), the function crashes.因此,如果功能有下一步(例如等待上传完成谷歌云存储),该功能将崩溃。

I've been able to replicate the bug with the following simple version:我已经能够使用以下简单版本复制错误:

async.waterfall([
   function (callback) {
       fs.writeFile("tmp/testfile.txt", "hello world", function(err) {
           callback(null);
       });
   },
   function (callback) {
       setTimeout(function(){
           callback(null)
       }, 10000);
   }
], function(err){console.log("done!"})

Any thoughts on what could be going wrong will be super appreciated!任何关于可能出问题的想法将不胜感激!

For posterity, the problem was that I was setting the tmp folder as simply "tmp".对于后代,问题是我将 tmp 文件夹设置为简单的“tmp”。 Turns out, you need to find the temp folder using os.tmpdir().事实证明,您需要使用 os.tmpdir() 找到临时文件夹。 Once you do that, it works fine.一旦你这样做,它就可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM