dockerode icon indicating copy to clipboard operation
dockerode copied to clipboard

unable to handle ssh network errors

Open GalGof opened this issue 1 year ago • 4 comments

example:

// process.on('uncaughtException', function (err) {
//   console.error("uncaughtException:", err.stack);
// });

const Docker = require('dockerode');


try {
  let docker = new Docker({
    host: "127.0.0.1",
    protocol: "ssh",
    username: "root",
    sshOptions: {
      host: "127.0.0.1",
      port: 4556,
    }
  });
  console.log('created')
  docker.ping()
    .then(()=>{console.log("ping ok")})
    .catch(()=>{console.error("ping failed")});
} catch (error) {
  console.error("catch", error);  
}

setInterval(()=>console.log(+new Date()), 60000)

expected: "ping failed" in console

actual: node process crushed

node .\test.cjs created ****\node_modules\docker-modem\lib\ssh.js:40 throw err; ^

Error: connect ECONNREFUSED 127.0.0.1:22 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16) { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 22, level: 'client-socket' }

is there no way to handle network connection errors to docker engine? simple example above - without node's uncaughtException handler - process crashes. but node's handler doesnt help as there is no way to tell where error occured. request to dockerode simly hangs without beeing rejected.

"node_modules/dockerode": {
  "version": "4.0.2",
"node_modules/docker-modem": {
  "version": "5.0.3",

GalGof avatar May 14 '24 20:05 GalGof

Hi! I also encountered this error, the (temporary) solution is to use a custom agent in the modem, waiting for this PR (https://github.com/apocas/docker-modem/pull/163/files) to be merged

SquirrelCorporation avatar May 21 '24 13:05 SquirrelCorporation

in simple case seems like working with it, but i wonder what's wrong with it if it's not merged for a year...

GalGof avatar May 21 '24 21:05 GalGof

I've created apocas/docker-modem#179 that fixes this issue and replaces the PR above with one that is built on the master branch and handles all the current error paths.

gaberudy avatar Sep 29 '24 13:09 gaberudy

This should be fixed in the latest version which merged my change to docker-modem

gaberudy avatar Jan 10 '25 03:01 gaberudy