mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
lib: clean after the cancel algorithm throw error
PR-URL: https://github.com/nodejs/node/pull/41366 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
This commit is contained in:
@@ -1911,9 +1911,12 @@ function readableStreamDefaultControllerError(controller, error) {
|
||||
|
||||
function readableStreamDefaultControllerCancelSteps(controller, reason) {
|
||||
resetQueue(controller);
|
||||
const result = controller[kState].cancelAlgorithm(reason);
|
||||
readableStreamDefaultControllerClearAlgorithms(controller);
|
||||
return result;
|
||||
try {
|
||||
const result = controller[kState].cancelAlgorithm(reason);
|
||||
return result;
|
||||
} finally {
|
||||
readableStreamDefaultControllerClearAlgorithms(controller);
|
||||
}
|
||||
}
|
||||
|
||||
function readableStreamDefaultControllerPullSteps(controller, readRequest) {
|
||||
|
||||
@@ -80,6 +80,36 @@ const {
|
||||
assert(r.locked);
|
||||
}
|
||||
|
||||
{
|
||||
// Throw error and return rejected promise in `cancel()` method
|
||||
// would execute same cleanup code
|
||||
const r1 = new ReadableStream({
|
||||
cancel: () => {
|
||||
return Promise.reject('Cancel Error');
|
||||
},
|
||||
});
|
||||
r1.cancel().finally(common.mustCall(() => {
|
||||
const controllerState = r1[kState].controller[kState];
|
||||
|
||||
assert.strictEqual(controllerState.pullAlgorithm, undefined);
|
||||
assert.strictEqual(controllerState.cancelAlgorithm, undefined);
|
||||
assert.strictEqual(controllerState.sizeAlgorithm, undefined);
|
||||
})).catch(() => {});
|
||||
|
||||
const r2 = new ReadableStream({
|
||||
cancel() {
|
||||
throw new Error('Cancel Error');
|
||||
}
|
||||
});
|
||||
r2.cancel().finally(common.mustCall(() => {
|
||||
const controllerState = r2[kState].controller[kState];
|
||||
|
||||
assert.strictEqual(controllerState.pullAlgorithm, undefined);
|
||||
assert.strictEqual(controllerState.cancelAlgorithm, undefined);
|
||||
assert.strictEqual(controllerState.sizeAlgorithm, undefined);
|
||||
})).catch(() => {});
|
||||
}
|
||||
|
||||
{
|
||||
const source = {
|
||||
start: common.mustCall((controller) => {
|
||||
|
||||
Reference in New Issue
Block a user