EventEmitter内存泄露

时间:2014-10-25 15:46:41

标签: node.js azure meteor storage blob

使用流星。我构建了一个meteor包,它有助于将文件上传到blob存储。我收到以下错误。此错误仅在5次中发生一次。

W20141025-15:22:40.195(5.5)? (STDERR) (node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
W20141025-15:22:40.546(5.5)? (STDERR) Trace
W20141025-15:22:40.546(5.5)? (STDERR)     at addListener (events.js:160:15)
W20141025-15:22:40.546(5.5)? (STDERR)     at /Users/user/boutfeeds/packages/jamesfebin:azure-blob-upload/.build.jamesfebin:azure-blob-upload/npm/node_modules/azure-storage/lib/common/services/storageserviceclient.js:399:31
W20141025-15:22:40.547(5.5)? (STDERR)     at /Users/user/boutfeeds/packages/jamesfebin:azure-blob-upload/.build.jamesfebin:azure-blob-upload/npm/node_modules/azure-storage/lib/common/services/storageserviceclient.js:516:5
W20141025-15:22:40.547(5.5)? (STDERR)     at SharedKey.signRequest (/Users/user/boutfeeds/packages/jamesfebin:azure-blob-upload/.build.jamesfebin:azure-blob-upload/npm/node_modules/azure-storage/lib/common/signing/sharedkey.js:81:3)
W20141025-15:22:40.547(5.5)? (STDERR)     at Object.StorageServiceClient._buildRequestOptions (/Users/user/boutfeeds/packages/jamesfebin:azure-blob-upload/.build.jamesfebin:azure-blob-upload/npm/node_modules/azure-storage/lib/common/services/storageserviceclient.js:498:27)
W20141025-15:22:40.634(5.5)? (STDERR)     at operation (/Users/user/boutfeeds/packages/jamesfebin:azure-blob-upload/.build.jamesfebin:azure-blob-upload/npm/node_modules/azure-storage/lib/common/services/storageserviceclient.js:255:10)
W20141025-15:22:40.634(5.5)? (STDERR)     at func [as _onTimeout] (/Users/user/boutfeeds/packages/jamesfebin:azure-blob-upload/.build.jamesfebin:azure-blob-upload/npm/node_modules/azure-storage/lib/common/services/storageserviceclient.js:422:11)
W20141025-15:22:40.635(5.5)? (STDERR)     at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

代码在这里

 azureUpload:function(fileName,accountName,key,container,callback) {

      var buffer = new Buffer(this.data);
      retryOperations = new azure.ExponentialRetryPolicyFilter();
      blobService = azure.createBlobService(accountName, key).withFilter(retryOperations);
      var blockId = this.blockArray[this.blockArray.length-1];
      var stream = new ReadableStreamBuffer(buffer);
      var self = this;
      Future = Npm.require('fibers/future');
      var myFuture = new Future;


      blobService.createBlockFromStream(blockId,container,fileName,stream,stream.size(),function(err,response)
            {

                if(err)
                {
                    myFuture.return();
                }
                else if (response)
                {     


                 if (self.bytesUploaded+self.data.length >= self.size)
                    {
                         blobService.commitBlocks(container, fileName, {LatestBlocks: self.blockArray}, function(error, result){
                                if(error){
                                 myFuture.return();

                                } else {
                                    myFuture.return({url:"https://"+accountName+".blob.core.windows.net/"+container+"/"+fileName});
                                }
                            });



                    }
                    else
                    {
                         myFuture.return();
                    }


                }

            });

        return myFuture.wait();



      }

您可以在此处查看完整源代码https://github.com/jamesfebin/azure-blob-upload/blob/master/azureupload.js(向下滚动至azureUpload函数)

1 个答案:

答案 0 :(得分:1)

节点默认有10个事件发射器。这可以通过向http服务器提供15个并发请求来轻松加载...这可以通过设置process.setMaxListeners(0)来停止。因此,它不会显示错误。请参阅此处http://nodejs.org/api/events.html