Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!