GraftJS / jschan

JavaScript port of libchan based around streams
MIT License
157 stars 9 forks source link

end and finish event not firing via SPDY #34

Closed heri16 closed 8 years ago

heri16 commented 9 years ago

I am creating an array of fs.createReadableStreams and putting them into a message. This message is then passed to my jschan/graft microservice, which pipes each file it into local fs.createWritableStreams.

Data, end, and finish events fire correctly when I am using the in-memory graftJS, and also when using spdy on localhost with a small file (< 3746 bytes). However, all three of the same events fail to fire when sending larger files over spdy jschan.

Node version is v0.10.35

Sender:

    // Convert filePaths into filestreams that can be sent via graft jschan
    if (msg.filePaths) {
      var fileStreams = {};
      msg.filePaths.forEach(function(filePath) {
        var fileName = path.basename(filePath);
        //var zlibCompress = zlib.createDeflate();
        var fileStream = fs.createReadStream(filePath);

        fileStream.resume();
        fileStream.on('data', function(chunk) {
          console.log('got %d bytes of data', chunk.length);
        });
        fileStream.on('end', function() { console.log('end'); });

        fileStreams[fileName] = fileStream;
      });
      msg.fileStreams = fileStreams;
    }

Receiver:

        // Save remote fileStreams to local temp directory.
        async.map(Object.keys(msg.fileStreams), function _writeStream(fileName, cb) {
          var fileStream = msg.fileStreams[fileName];
          var outPath = path.join(dirPath, fileName);
          var outStream = fs.createWriteStream(outPath);
          console.log(outPath);

          // end event does not fire
          fileStream.resume();
          fileStream.on('data', function(chunk) {
            console.log('got %d bytes of data', chunk.length);
          });
          fileStream.on('end', function() { console.log('end'); });

          // finish event does not fire 
          fileStream.pipe(outStream).on('error', function(err) {
            setImmediate(cb, err);
          }).on('finish', function() {
            setImmediate(cb, null, outPath);
          });

        }, function(err, filePaths) {
          if (err) { cleanupTmp(); throw err; }
          ...
        });

Would really appreciate the help nailing this bug down.

mcollina commented 9 years ago

Sorry for the late reply, I have very low bandwidth for this now.

Can you please test https://github.com/GraftJS/jschan/pull/32? It might solve the issue, in case I'll get it released.

AdrianRossouw commented 8 years ago

i merged that change, and we also moved the spdy transport to a separate repo.

recreate there if this still exists.

https://github.com/GraftJS/jschan-spdy

heri16 commented 8 years ago

Is this fixed?