Repository navigation
Rework request cancellation - #846
Conversation
| @@ -1672,13 +1718,8 @@ class Connection extends EventEmitter { | |||
| const message = 'Requests can only be canceled in the ' + this.STATE.SENT_CLIENT_REQUEST.name + ' state, not the ' + this.state.name + ' state'; | |||
There was a problem hiding this comment.
When cancel() is called after a timeout, a debug message is still displayed, see #545.
There was a problem hiding this comment.
I want to deprecate .cancel on Connection, and thus did not touch this function more than necessary. We could change this function to:
if (!this.request) {
return false;
}
if (this.request.canceled) {
return false;
}
this.request.cancel();
return true;And still deprecate (and later remove) this function? 🤔
|
I have made some comments, but the fundamental problem is that the program logic in The TDS protocol state machine should be encapsulated in a separate module and isolated from the rest. There should be clear documented APIs for every module. Private and public variables should be distinguished, etc. |
0597d57 to
2f61cca
Compare
According to 3.2.5.8 of the MS-TDS specification, all data received for a request after sending the attention message MUST be discarded. BREAKING CHANGE: Canceled requests will no longer receive any data.
This will have the side effect that any data that is received after the timeout was triggered will be discarded. This mirrors the way user-initiated request cancellation behaves. BREAKING CHANGE: Timed out requests will no longer receive any data.
2f61cca to
52967ee
Compare
`BulkRequests` can now be canceled, both when in streaming as well as non-streaming mode. In case an error happens in the internal row transformation stream on a streaming `BulkLoad`, the in-flight request will be canceled and the error will be propagated to the request callback.
52967ee to
c54f1fe
Compare
This adds a `.cancel` method to both `Request` as well as `BulkLoad`, which can be called before or during request execution.
This adds the missing cancel timer, as described by the MS-TDS specification. It controls the maximum time spent waiting for a query cancellation. In case the timer fires, the connection will be closed, and the current request's callback will be called with an error.
c54f1fe to
74682a4
Compare
Yeah, you're totally right. 😞 The way the state machine is currently translated to code is... not quite optimal. I'm trying to move the code in a better direction, through a small set of changes that I have in mind. The first set of changes is over #847. It's nothing revolutionary, but I feel like doing small, iterative changes is going to yield results as soon as possible and will help us move in the right direction quicker. |
|
🎉 This PR is included in version 5.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This is an attempt to rework how request cancellation works, to make it more generic (it now works with regular requests and both streaming as well as non-streaming bulk loads) and more conformant to the MS-TDS spec.
This also adds a new
.cancelmethod on theRequestandBulkLoadclasses, and deprecates thecancelmethod on theConnectionclass itself.The changes in 8c9ce1d warrant a major version bump, as they change the behaviour of requests that are canceled after they were sent to the server. Instead of continuing to forward various events from the token stream parser to the canceled request, all this information will be "discarded", as described in
3.2.5.8 Sent Attention Stateof the MS-TDS specification:Fixes: #545
Fixes: #534
Fixes: #566