Skip to content

Commit

Permalink
Fixing race condition on job cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
kruss committed Jul 17, 2023
1 parent 2f3d35b commit 088142d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions application/apps/rustcore/ts-bindings/src/native/native.jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,27 @@ export class Base {
sequence: number,
alias: string,
): CancelablePromise<Output> {
return new CancelablePromise((resolve, reject, cancel, refCancel, _self) => {
return new CancelablePromise((resolve, reject, cancel, refCancel, self) => {
if (this._state !== State.inited) {
return reject(new Error(`Session isn't inited`));
}
this.queue.add(sequence, alias);
refCancel(() => {
this.abort(sequence).catch((err: Error) => {
if (self.isCompleted()) {
this.logger.warn("Job was already completed on aborting");
return;
}
this.logger.error(`Fail to cancel ${error(err)}`);
});
});
task.then((nativeOutput: string) => {
try {
const result: JobResult<Input> = JSON.parse(nativeOutput);
if (result === 'Cancelled') {
if (result === 'Cancelled' || self.isCanceling()) {
if (result !== 'Cancelled' && self.isCanceling()) {
this.logger.warn("Job result dropped due canceling");
}
cancel();
} else if (convert === undefined) {
resolve(result.Finished as unknown as Output);
Expand Down

0 comments on commit 088142d

Please sign in to comment.