Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if this[kWebSocket] = undefined , then must check it exists else where #1606

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 21 additions & 6 deletions lib/websocket.js
Expand Up @@ -743,6 +743,7 @@ function sendAfterClose(websocket, data, cb) {
*/
function receiverOnConclude(code, reason) {
const websocket = this[kWebSocket];
if(!websocket){ return }

websocket._socket.removeListener('data', socketOnData);
websocket._socket.resume();
Expand All @@ -761,7 +762,9 @@ function receiverOnConclude(code, reason) {
* @private
*/
function receiverOnDrain() {
this[kWebSocket]._socket.resume();
const websocket = this[kWebSocket];
if(!websocket){ return }
websocket._socket.resume();
}

/**
Expand All @@ -772,6 +775,7 @@ function receiverOnDrain() {
*/
function receiverOnError(err) {
const websocket = this[kWebSocket];
if(!websocket){ return }

websocket._socket.removeListener('data', socketOnData);

Expand All @@ -787,7 +791,9 @@ function receiverOnError(err) {
* @private
*/
function receiverOnFinish() {
this[kWebSocket].emitClose();
const websocket = this[kWebSocket];
if(!websocket){ return }
websocket.emitClose();
}

/**
Expand All @@ -797,7 +803,9 @@ function receiverOnFinish() {
* @private
*/
function receiverOnMessage(data) {
this[kWebSocket].emit('message', data);
const websocket = this[kWebSocket];
if(!websocket){ return }
websocket.emit('message', data);
}

/**
Expand All @@ -808,6 +816,7 @@ function receiverOnMessage(data) {
*/
function receiverOnPing(data) {
const websocket = this[kWebSocket];
if(!websocket){ return }

websocket.pong(data, !websocket._isServer, NOOP);
websocket.emit('ping', data);
Expand All @@ -820,7 +829,9 @@ function receiverOnPing(data) {
* @private
*/
function receiverOnPong(data) {
this[kWebSocket].emit('pong', data);
const websocket = this[kWebSocket];
if(!websocket){ return }
websocket.emit('pong', data);
}

/**
Expand All @@ -834,6 +845,7 @@ function socketOnClose() {
this.removeListener('close', socketOnClose);
this.removeListener('end', socketOnEnd);

if(!websocket){ return }
websocket.readyState = WebSocket.CLOSING;

//
Expand All @@ -850,7 +862,7 @@ function socketOnClose() {
websocket._receiver.end();

this.removeListener('data', socketOnData);
this[kWebSocket] = undefined;
this[kWebSocket] = undefined; // if we clear this out, we must check it exists else where.

clearTimeout(websocket._closeTimer);

Expand All @@ -872,7 +884,9 @@ function socketOnClose() {
* @private
*/
function socketOnData(chunk) {
if (!this[kWebSocket]._receiver.write(chunk)) {
const websocket = this[kWebSocket];
if(!websocket){ return }
if (!websocket._receiver.write(chunk)) {
this.pause();
}
}
Expand All @@ -884,6 +898,7 @@ function socketOnData(chunk) {
*/
function socketOnEnd() {
const websocket = this[kWebSocket];
if(!websocket){ return }

websocket.readyState = WebSocket.CLOSING;
websocket._receiver.end();
Expand Down