0

I am trying to track down why my code is failing with this error:

 { Error: connect ECONNREFUSED 127.0.0.1:443
     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1082:14)
   errno: 'ECONNREFUSED',
   code: 'ECONNREFUSED',
   syscall: 'connect',
   address: '127.0.0.1',
   port: 443 }

and the stack trace for that error looks like this:

 Error: connect ECONNREFUSED 127.0.0.1:443
     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1082:14)

I am making a network connection, but I am not trying to connect to localhost.

The network code I am using works just fine (and connects to the right host) in other contexts.

I'm using node 11.6.0 as supplied by brew install, and it looks like the only occurrence of the string "net.js" in the brew "Cellar" directory structure is in the node binary itself. In other words, even after

 brew install --build-from-source node

running

 find /usr/local/Cellar/node/11.6.0 -type f | xargs fgrep -l net.js

only finds one file: /usr/local/Cellar/node/11.6.0/bin/node and there's no net.* files in that directory tree.

If it matters, my code which seems to trigger this error looks like this:

  const get_json_with_auth= async (channel, url) => {
    const parsed_url= URL.parse(url);
   return new Promise((good, fail) => {
     let request= require('https').get({
       hostname: parsed_url.hostname,
       path: parsed_url.path,
       headers: {
         Authorization: get_auth('GET', channel, url)
       }
     });
     console.log('url', url);
     request.on('response', response=> {
       const chunks= [];
       response.on('data', data=> chunks.push(data));
       response.on('end', ()=> good(JSON.parse(Buffer.concat(chunks).toString())));
     });
     request.on('error', err=> fail(err));
   });
 };

(I'm on OSX high sierra here.)

But, once again, the host name in the url I'm using does not resolve to localhost (and works just fine in other contexts).

How do I isolate a problem like this?

rdm
  • 658
  • 5
  • 16

1 Answers1

2

Running my code with the environmental variable NODE_DEBUG='net,tls,http,https' gave me enough information to recognize (and isolate) the problem.

rdm
  • 658
  • 5
  • 16
  • and what is the problem? im running on the same issue. – Gel Mar 08 '19 at 19:23
  • In my case, the problem was a typo, and the request I thought I was generating was different from the request that I was generating. Once I saw what the request actually was, I knew where to look to fix that problem. – rdm Mar 10 '19 at 16:24