sergi/jsftp

jsftp intermittently skips `end` event on socket

Closed this issue · 3 comments

When getting file using Ftp.prototype.get socket intermittently emits close event without emitting end event. This causes downstream consumers (like https://github.com/sergi/jsftp/blob/master/lib/jsftp.js#L438) to hang until timeout kicks in.

Observed behavior:

FTP DEBUG:  response
{
  "code": 226,
  "text": "226 Transfer complete.",
  "isMark": false,
  "isError": false
}
ftp socket emits `close`

Expected behavior:

FTP DEBUG:  response
{
  "code": 226,
  "text": "226 Transfer complete.",
  "isMark": false,
  "isError": false
}
ftp socket emits `end`
ftp socket emits `close`

Maybe my issue is related, but not sure as this is all way above my pay grade.

When I run the sample list or get examples, I am left with a blinking cursor and not at the command prompt.

No big deal. I've been able to get the files off a server I needed. All I do is hit control-C.

But it would be nice to know what to do to terminate the script.

In any case: Bravo Sergi for making my life a lot easier. Thank you!

Hey @doronin, this scenario can happen when the socket is closed due to an error (http://nodejs.org/api/net.html#net_event_error_1). In that case, an error event will be emitted immediately followed by a close event with a boolean true parameter.

So, one way to see if that's what's happening is to listen to the close event and see if it comes with a parameter with value true. Can you try this in your scenario? Thanks!