4
votes

I have a system that is running on Node 8.11.1 on AWS. There is a function that writes logs to another server. This function takes a request object that it logs.

My problem arises during the actual POST attempt, giving me the following error:

Error: write EPROTO 139746875082624:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:827:

I cannot see anything wrong with my code.
Why is the error occurring, and what can I do to fix it?

Here is the code inside of the function:

const https = require('https');    
try
{
   const postData = "New log finished " + JSON.stringify(request, null, 2);

   const options =
   {
      hostname: LOG_DOMAIN,
      port: LOG_PORT,
      path: '/',
      method: 'POST'
   };

   const req = https.request(options);
   req.on('error', (e) =>
   {
      console.error("ERROR writing logs: " + e);
   });
   req.write(postData);
   req.end();
}
catch (e)
{
   console.log(e);
}

LOG_DOMAIN and LOG_PORT are variables passed to the function.

1
What is the value of LOG_PORT? - Aravind Voggu
@AravindVoggu Excellent question. LOG_DOMAIN and LOG_PORT are variables passed to the function. I have updated the original post to reflect this. - JSBach
Yes they are, I'm looking for the 'value' :) . httpS uses port 443 and http only uses port 80. If LOG_PORT value is 80 and you try to use httpS, you can get an error like this. Can you check and confirm LOG_PORT is set to 443? Also post the value of LOG_DOMAIN while you are at it, just to be sure. - Aravind Voggu
@AravindVoggu I am posting to an ELK server which holds the logs, and I am using a port other than 443. I am reticent to post the actual domain for security purposes of my organization. That said, am I unable to securely post on a port besides 443? The domain expects another port, but I do not know if the Node module is limited to only that port. - JSBach
I will check with our platform team to see if there are any logs around that. @AravindVoggu I really appreciate your time!! - JSBach

1 Answers

3
votes

After further research, it appears that Aravind Voggu (see comments) was in the right vein: the error comes from attempts to use HTTPS for a server that only allows HTTP.

The OpenSSL dies when attempting to secure a connection to something that is unsecured.

The only change required to make my code work correctly was to remove the "s" from "https" in the locations used.

const http = require("http");