NodeSSH Reconnect Issue: isConnected() Returns TRUE Even When Connection Unsuccessful

Aperta
#459 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
node.js, typescript
Ambito
networking

Direzione di ricerca

Inizia dal metodo connect di TypeScript e traccia quando viene assegnato this.connection rispetto agli eventi ready, error, end e close di SSH2. Conferma la modifica verificando che isConnected() non segnali una connessione dopo un reconnect non riuscito; l'issue non indica alcun file né alcun test da eseguire.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I am encountering an issue which seems to be related to ISSUE-429, where the problem still persists. As im not aware of any pitfalls in the code, i have created a suggestion to resolve the issue.

Description:

The problem is caused by the assignment of the this.connection property before the connection promise resolves. Specifically, the this.connection property is being set before the connection.on('ready') event is triggered.

Proposed Solution:
To resolve this issue, I suggest moving the assignment of this.connection inside the connection.on('ready') event in the connect method:

public async connect(givenConfig: Config): Promise<this> {
  // ... (Rest of the code remains the same)

  const connection = new SSH2.Client();

  await new Promise<void>((resolve, reject) => {
    connection.on('error', reject);
    if (config.onKeyboardInteractive) {
      connection.on('keyboard-interactive', config.onKeyboardInteractive);
    }
    connection.on('ready', () => {
      connection.removeListener('error', reject);
      this.connection = connection; // Move this line inside the 'ready' event
      resolve();
    });
    connection.on('end', () => {
      if (this.connection === connection) {
        this.connection = null;
      }
    });
    connection.on('close', () => {
      if (this.connection === connection) {
        this.connection = null;
      }
      reject(new SSHError('No response from server', 'ETIMEDOUT'));
    });
    connection.connect(config);
  });

  return this;
}

Will i help?
Yeah, let us discuss and i can create a PR :)

Lingua principale
TypeScript
Stelle
1k
Fork
94
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di steelbrain/node-ssh

Tutte le issue di steelbrain/node-ssh

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.