Skip to content

socket.end() in handleUpgrade (server.js) cause "upstream prematurely closed connection while reading response header from upstream" in nginx #283

@beatjoerg

Description

@beatjoerg

If there is an upgrade Request with an invalid sid the current implementation closes the connection immediatly. Which cause an error on nginx ("upstream prematurely closed connection while reading response header from upstream"). If I comment out the socket.end() it returns a 400 Header, which I expect. I have other failuers with the same error, but did not find yet the cause.
Nginx Proxy Headers are set correctly.

Server.prototype.handleUpgrade = function(req, socket, upgradeHead){
  this.prepare(req);

  var self = this;
  this.verify(req, true, function(err, success) {
    //if (!success) {
    //  socket.end();
    //  return;
    //}

    var head = new Buffer(upgradeHead.length);
    upgradeHead.copy(head);
    upgradeHead = null;

    // delegate to ws
    self.ws.handleUpgrade(req, socket, head, function(conn){
      self.onWebSocket(req, conn);
    });
  });
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions