icetee / node-ftp

An FTP client module for node.js
MIT License
25 stars 16 forks source link

Callback not called in .list when ECONNRESET #16

Open coyotte508 opened 4 years ago

coyotte508 commented 4 years ago

After creating a ftp, doing many operations on it, I get this:

Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:205:27) {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read'
}

This is from ftp.on('error', ...).

However the .list callback wasn't called at all. It's never called, and my logic just halts.

Here's where I call .list:

  return await new Promise<Array<{name: string, type: string}>>((resolve, reject) => {
      console.log("call underlying list", pathStr);
      this._ftp.list(pathStr, (err: Error, list: Ftp.ListingElement[]) => {
        if (err) {
          console.log("ftp list ended with error");
          reject(err);
        }
        console.log("ftp list ended with success");
        resolve(list);
      });
    });

Here's where I handle the more general error event, before the connection event:

return await new Promise<string>((resolve, reject) => {
      this._ftp.on("ready", () => {
        this._connected = true;
        this._connecting = false;
        console.log("ftp connected and ready");
        resolve("/");
      });
      this._ftp.on("error", err => {
        this._connected = false;
        this._connecting = false;
        console.error("ftp error", err);
        reject(err);
      });
      this._ftp.on("close", () => {
        console.log("ftp closed");
        this._connected = false
      });
      this._ftp.on("end", () => {
        console.log("ftp end");
        this._connected = false
      });
      this._ftp.connect(this._credentials);
    });

And here's the log of my application:

call underlying list /public/IMR_Donnees_Saisies/tc/flux/2020/05/12/9401/1618
ftp error Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:205:27) {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read'
}
ftp closed

So ftp does emit the error and close events, but the callback of list is never called.