mscdex / node-ftp

An FTP client module for node.js
MIT License
1.13k stars 246 forks source link

ftp.get() hangs for 60 seconds in node v10, but not in node v8 #228

Closed broofa closed 3 years ago

broofa commented 5 years ago

Specifically, when I run the test case below (fetching a single file from a local FTP server), it takes ~53msecs on node v8, but 60000msecs on node 10.

Exact console output listed below as well.

const Ftp = require('ftp');

const host = '192.168.1.201';
const user = 'anonymous';
const fileName = 'axis.dg';

let client = new Ftp();

client.on('ready', () => {
  console.time('get()');
  client.get(fileName, (err, stream) => {
    stream.on('end', () => {
      console.timeEnd('get()');
      client.destroy();
    });
  });
});

client.connect({host, user});

The exact console output, if it helps:

$ nvm use 8
Now using node v8.11.4 (npm v5.6.0)

$ node test.js
get(): 53.476ms

$ nvm use 10
Now using node v10.11.0 (npm v6.4.1)

$ node test.js
get(): 60081.924ms
kingeaglewang commented 5 years ago

After update node version from 8.9.2 to 10.2.0, I also encounter this problem. But don't know why?

broofa commented 5 years ago

@kingeaglewang: Note that this module appears to have been abandoned (3+ years since a new version published, 1+ years since a contributer has commented on an issue).

I've switched to the basic-ftp module, and have been working with the author on a new release (see the feature/v3 branch).

Edit: Readers may also be interested in @icetee's fork at https://www.npmjs.com/package/@icetee/ftp

zhang110912 commented 4 years ago

I also encounter this problem after upgrade node version to 10.16.5, Is there a bug triggered on 10.x node version ? any suggestion will be appreciated!

std4lqi commented 4 years ago

I did some investigation. Node.JS v10 changed to use the way for socket clean up at EOF.

Node.JS v8: Find onread() in https://github.com/nodejs/node/blob/v8.16.2/lib/net.js.

Node.JS v10 Find onStreamRead() in https://github.com/nodejs/node/blob/v10.17.0/lib/internal/stream_base_commons.js.

I'm not sure about the actual difference yet.

But I noticed in connection.js, this node-ftp library sends MODE S when all data is received, switching backing to stream mode. It might be required by compress mode, switching to MODE Z already, and switching back to MODE S.

After commenting out the line of self.send('MODE S'..., keeping _emit('end') and _emit('close'), I don't have 2-min hang on Node.JS v10 any more.

function ondone() {
        console.log(`${Date.now()} done=${done} lastreply=${lastreply}`);
      if (done && lastreply) {
        self._send('MODE S', function() {
          source._emit('end');
          source._emit('close');
        }, true);
      }
    }
broofa commented 3 years ago

@mscdex Time to archive this repo / hand off ownership to someone else? (... conspicuously not volunteering, however. 😝 )