Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
Why require 'child_process'.exec function hang occasionally

I develop a vscode extension with TypeScript,which provides a function for remote connection test. But occasionally this connection test command gets stuck and never returns。

My code is like this:

const util = require('util');
const exec = util.promisify(require('child_process').exec);

export class ConnectService {
    
      async testConnectionByCmd(instanceInfo: any) {
          //some code to get connection info
          ……
          // test connection by cmd
                let cmd = `ssh -tt -o StrictHostKeyChecking=no -i ${IdentityFile} ${User}@${HostName} -p ${Port} echo $? "exit 0"`;
                Logger.info('check connection cmd : ' + cmd);
                return new Promise(async resolve => {
                    let stdout, stderr;
                    try {
                        ({stdout, stderr} = await exec(cmd));   // hang at here sometime
                        Logger.info('exec(cmd).stdout: ' + stdout);  // and this log is not printed
                        Logger.info('exec(cmd).stderr: ' + stderr);
                    } catch (e: any) {
                        ({stdout, stderr} = e);
                    }
                    return resolve({stdout, stderr, HostName});
                });
    }

When the code is hang here, I open a terminal and execute the command in terminal, it returns normally and quickly, which means the network connection of the remote host is normal。 But the ts code still hangs here and never return.

What is the reason for this? Thank you!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda