ayojs / ayo

A fork of Node.js. Humans before technology.
Other
1.66k stars 97 forks source link

src: cancel pending delayed platform tasks on exit #120

Closed addaleax closed 6 years ago

addaleax commented 6 years ago

Worker threads need an event loop without active libuv handles in order to shut down. One source of handles that was previously not accounted for were delayed V8 tasks; these create timers that would be standing in the way of clearing the event loop.

To solve this, keep track of the scheduled tasks in a list and close their timer handles before the corresponding isolate/loop is removed from the platform.

It is not clear from the V8 documentation what the expectation is with respect to pending background tasks at the end of the isolate lifetime; however, an alternative approach of executing these scheduled tasks when flushing them led to an infinite loop of tasks scheduling each other; so it seems safe to assume that the behaviour implemented in this patch is at least acceptable.

Checklist
Affected core subsystem(s)

src/node_platform

addaleax commented 6 years ago

@ayojs/core Also definitely a bit trickier. I have tried to write a helpful commit message but I know this is not the most well-known area of Node/Ayo :)

addaleax commented 6 years ago

Landed in 9590bcb02dd164ff5dacb1de1e06a786a55c50ab