apocas / dockerode

Docker + Node = Dockerode (Node.js module for Docker's Remote API)
Apache License 2.0
4.29k stars 461 forks source link

unable to handle ssh network errors #764

Open GalGof opened 2 months ago

GalGof commented 2 months ago

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",
SquirrelCorporation commented 2 months ago

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

GalGof commented 2 months ago

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