Skip to content

Zone.js cancelTask throws an error when trying to cancel a previously cancelled task #45711

@redoxerjosh

Description

@redoxerjosh

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

We have code running a Knexjs migration which is wrapped in some code that we use Zonejs for tracing execution. It appears that by the time Zonejs tries to cancel a task, it is already in a notScheduled state.

A similar circumstance was fixed awhile back in the context of runTask, see angular/zone.js#778

It may be a simple fix to add a similar guard in cancelTask at https://github.com/angular/angular/blob/master/packages/zone.js/lib/zone.ts#L959

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

{"type":"Error",
 "message":"eventTask 'Client_PG.addListener:start': can not transition to 'canceling', expecting state 'scheduled' or 'running', was 'notScheduled'.",
 "stack_trace":[
   "Error: eventTask 'Client_PG.addListener:start': can not transition to 'canceling', expecting state 'scheduled' or 'running', was 'notScheduled'.",
   "    at ZoneTask._transitionTo (/opt/nodejs/node_modules/zone.js/dist/zone-node.js:532:23)",
   "    at Zone.cancelTask (/opt/nodejs/node_modules/zone.js/dist/zone-node.js:270:18)",
   "    at Client_PG.proto.<computed> [as removeListener (/opt/nodejs/node_modules/zone.js/dist/zone-node.js:1959:43)",
   "    at /opt/nodejs/node_modules/knex/lib/util/make-knex.js:284:19",
   "    at Array.forEach (<anonymous>)","    at redefineProperties (/opt/nodejs/node_modules/knex/lib/util/make-knex.js:283:29)",
   "    at Object.withUserParams (/opt/nodejs/node_modules/knex/lib/util/make-knex.js:207:7)",
   "    at Function.value (/opt/nodejs/node_modules/knex/lib/util/make-knex.js:90:29)",
   "    at new Migrator (/opt/nodejs/node_modules/knex/lib/migrate/Migrator.js:34:26)",
   "    at Function.get (/opt/nodejs/node_modules/knex/lib/util/make-knex.js:49:14)"]}

Please provide the environment you discovered this bug in (run ng version)

Node: 16.14.0
Knex: 0.21.21
Zone.js: 0.8.29

Anything else?

No response

Metadata

Metadata

Assignees

Labels

P4A relatively minor issue that is not relevant to core functionsarea: zonesIssues related to zone.jsbug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions