Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda