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

Calling cancel doesn't work on PullTransfer #144

Open
ddubrow-samsung opened this issue Jul 3, 2023 · 1 comment
Open

Calling cancel doesn't work on PullTransfer #144

ddubrow-samsung opened this issue Jul 3, 2023 · 1 comment

Comments

@ddubrow-samsung
Copy link

I believe this is due to this check in the cancel method
while (promise._isCancellable())
This check is in this cancel function
Promise.prototype["break"] = Promise.prototype.cancel

When this check is made, the promise is always resolved so it's not cancellable.

@dfriederich
Copy link

I do work with Alyx (ddubrow). When looking why the cancellation of a pull request does not work, I have the impression the (or one of) issue is the readNext function inside of _readData in src/adb/sync.ts
Not an expert in the special cancellation support of bluebird's Promise implementation, but when looking at the code:

const readNext = () => { return this.parser.readAscii(4).then((reply) => { switch (reply) { case Protocol.DATA: return this.parser.readBytes(4).then((lengthData) => { const length = lengthData.readUInt32LE(0); return this.parser.readByteFlow(length, transfer).then(() => { readNext(); }); }); // cut ... } }); }; const reader = readNext() .catch(Bluebird.CancellationError, () => this.connection.end()) .catch((err: Error) => transfer.emit('error', err)); const cancelListener = () => reader.cancel(); transfer.on('cancel', cancelListener);

It seems evident to me that the promise returned by the recursive invocation of readNext() is just ignored, hence does not get canceled (and also gets dropped, hence no error reporting, unhandled promise failures, or not?)

So maybe cancellation only works while receiving data for the first block, 65k? I do observe that calling cancel has no effect when calling it later on.

Could we fix this issue by a trivial cancel handling, by setting a flag when canceling, and then stop the recursion by not calling readNext() again?

I guess we could also try to cancel the current reader's promise directly, but for my use just stopping after a 65k block instead of never is a huge improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants