node-request - Getting error "SSL23_GET_SERVER_HELLO:unknown protocol"

I'm using the node-request module, regularly sending GET requests to a set of URLs and, sometimes, getting the error below on some sites.

Error: 29472:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:683

The problem is that I don't get this error always or always on the some URLs, just sometimes. Also, it can't be ignored with "strictSSL: false".

I have read that this can be related to me sending SSL requests with the wrong protocol (SSLv2, SSLv3, TLS..). But this doesn't explain why it happens irregularly.

Btw, I'm running nodejs on a Win 2008 server.

Any help is appreciated.

You will get such error message when you request HTTPS resource via wrong port, such as 80. So please make sure you specified right port, 443, in the Request options.

This was totally my bad.

I was using standard node http.request on a part of the code which should be sending requests to only http adresses. Seems like the db had a single https address which was queried with a random interval.

Simply, I was trying to send a http request to https.

Some of the sites are speaking SSLv2, or at least sending an SSLv2 server-hello, and your client doesn't speak, or isn't configured to speak, SSLv2. You need to make a policy decision here. SSLv2 should have vanished from the face of the earth years ago, and sites that still use it are insecure. However, if you gotta talk to them, you just have to enable it at your end, if you can. I would complain to the site owners though if you can.

var https = require('https');
https.globalAgent.options.secureProtocol = 'SSLv3_method';

It sounds like you just need to have some retry logic so intermittent errors don't hang you up.

function faultTolerantRequest (url, trys, retryTime, cb) {
  var attempts = 0;
  function requestFinished (err, res, body) {
    if (err) {
      if (attempts < trys) {
        return setTimeout(tryRequest, retryTime);
      }
      return cb(err);
    }
    return cb(err, res, body);
  }
  function tryRequest () {
    attempts++;
    return request(url, requestFinished);
  }
  return tryRequest();
}