Petey Howell
Petey Howell

Reputation: 189

NodeJS HTTPS Error (520)

I've no idea what this error, or how to fix it. Still learning NodeJS, so sorry for noobness.

I am also using Cloudflare.

node: ../src/util-inl.h:196: TypeName* node::Unwrap(v8::Local<v8::Object>) 
[with TypeName = node::TLSWrap]: Assertion `(object->InternalFieldCount()) > (0)' 
failed.

This is the code I'm using.

var options = {
    key: fs.readFileSync('/my.key'),
    cert: fs.readFileSync('/my.pem')
}   

var serverPort = 2096;
var app = require('express')();
var server = https.createServer(options, app);
var io = require('socket.io')(server);

server.listen(serverPort, function(){
    console.log('Connected on port *:%s', serverPort);
});

Then on the client side

var socket = io.connect('https://example.com:2096');

As soon as I do something, the console shows this

WebSocket connection to 'wss://example.com:2096/socket.io/?EIO=3&transport=websocket&sid=cTlTQnHvcv0LwbBdAAAA' failed: Error during WebSocket handshake: Unexpected response code: 520

Upvotes: 0

Views: 2477

Answers (1)

Osama Bari
Osama Bari

Reputation: 598

The 520 error is essentially a “catch-all” response for when the origin server returns something unexpected or something that is not tolerated/interpreted (protocol violation or empty response).

While the 520 error can be triggered by very unique and strange edge-case scenarios, they are generally caused by:

  • Connection resets (following a successful TCP handshake)
  • Headers exceed Cloudflare’s header size limit (over 8kb)
  • Empty response from origin
  • Invalid HTTP response
  • HTTP response missing response headers

Upvotes: 1

Related Questions