Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js v8.11.1 EPROTO error when attempting to POST using https module

Tags:

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.

like image 558
JSBach Avatar asked Nov 16 '18 17:11

JSBach


1 Answers

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");
like image 190
JSBach Avatar answered Oct 12 '22 02:10

JSBach