-
Notifications
You must be signed in to change notification settings - Fork 437
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
Stop request timer when first packet of response message is received #530
Changes from 1 commit
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 |
---|---|---|
|
@@ -522,7 +522,10 @@ class Connection extends EventEmitter { | |
this.socket.on('close', this.socketClose); | ||
this.socket.on('end', this.socketEnd); | ||
this.messageIo = new MessageIO(this.socket, this.config.options.packetSize, this.debug); | ||
this.messageIo.on('data', (data) => { this.dispatchEvent('data', data); }); | ||
this.messageIo.on('data', (data) => { | ||
this.clearRequestTimer(); | ||
this.dispatchEvent('data', data); | ||
}); | ||
this.messageIo.on('message', () => { | ||
return this.dispatchEvent('message'); | ||
}); | ||
|
@@ -567,7 +570,8 @@ class Connection extends EventEmitter { | |
|
||
clearRequestTimer() { | ||
if (this.requestTimer) { | ||
return clearTimeout(this.requestTimer); | ||
clearTimeout(this.requestTimer); | ||
this.requestTimer = undefined; | ||
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. For consistency with the rest of the file, please change this to: this.requestTimer = void 0; 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. Remove the call to clearTimeout under SENT_CLIENT_REQUEST:message. We don't need that now. 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. We have a requestTimeout integration test in connection-test.coffee that tests the old behavior. It's still relevant, so we can keep it. To test the new behavior, we can add a test that'll sleep for a little over the requestTimeout amount in the first invocation of 'row' event handler. With old behavior that would cause a timeout, whereas with the new behavior it should not. 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. 'undefined' is preferred over 'void 0'. 'void 0' is a relic of the CoffeeScript to JavaScript conversion. 😔 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 thread seems to suggest 'void 0' is safer - http://stackoverflow.com/questions/5716976/javascript-undefined-vs-void-0. If we like 'undefined' I'll send a PR to change all 'void 0' s to undefined for consistency. Otherwise it'll keep bugging me :-) 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 think it's not possible to design a reasonable and better test case without calling Request.pause(). But you could try yourself.
I meant to move the existing call of clearRequestTimer() from STATE.SENT_CLIENT_REQUEST.events.message to STATE.SENT_CLIENT_REQUEST.exit, in addition to the new call. That way we would have a fail-safe for future code modifications. Additionally it would also be safe to call clearRequestTimer() at the start of createRequestTimer(). But with the current situation, everything looks OK. 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 tried and you're right. Sleep in 'row' does not help. 'message' event gets handled before timeout callback is invoked and clears the timer.
That makes sense. Please go ahead and make that update. 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 would be great. There's quite a bit of leftovers from that conversion, and getting those cleaned up would be 💖.
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 think we could test a timeout by pausing one of the underlying streams after receiving the first row (and before receiving it). It's pretty ugly test case and I'm not sure whether testing this is worth it. 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. Probably not worth it, considering the real pause/resume is coming soon and we'll have clean tests. |
||
} | ||
} | ||
|
||
|
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.
This technically belongs under SENT_CLIENT_REQUEST.data. Can't come up with a case where this breaks anything though...