-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Do not waste time compressing when socket is closed #1464
Changes from 7 commits
d160344
b265319
d75800e
c936a4c
d780571
0444d5c
e2f4342
edda00c
88c5474
35105d2
3303832
20e9d85
dc90638
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,24 @@ class Sender { | |
this._bufferedBytes = 0; | ||
this._deflating = false; | ||
this._queue = []; | ||
|
||
this._socket.prependOnceListener('close', () => { | ||
const err = new Error( | ||
`WebSocket is not open: readyState ${this._socket.readyState} ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit misleading because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Would it be better to have a simple generic message here? The original intent was to provide consistency with what the user would get as an error regardless of whether their send attempt was queued or not, but since it was already inconsistent a generic message wouldn't break anything here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can pass the
What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been trying to avoid that because I don't like how it hard links Sender to WebSocket. A Sender doesn't need a WebSocket to function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, the same is also true for the |
||
); | ||
|
||
while (this._queue.length) { | ||
const params = this._queue.shift(); | ||
|
||
this._bufferedBytes -= params[1].length; | ||
|
||
const cb = params[params.length - 1]; | ||
|
||
if (typeof cb === 'function') { | ||
cb(err); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need
prependOnceListener()
? Or is it used only to ensure that the listener is added before the one added inwebsocket.js
? In the latter case I would just add a comment inWebSocket#setSocket()
to specify that theSender
must be instantiated before adding the'close'
listener to thenet.Socket
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out we do actually need it. I was testing a different ready state in my initial pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm ok, that's strange as this is added before the other anyway. I'm not a fan of
prependOnceListener()
because it will add the listener before all other listeners including the ones added by Node.js itself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me poke it again, I may end up blaming jet lag. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, going to blame jet lag. Sorry for the confusion. We do not need prepend, I'll switch it over to the comment instead. The issue was I was switching
prepend
toonce
in the Sender but not in the MockSocket for the test.