laverdet / node-fibers

Fiber/coroutine support for v8 and node.
MIT License
3.56k stars 224 forks source link

Restore an *actual* async resource, not just the ID #466

Open znewsham opened 1 year ago

znewsham commented 1 year ago

I know the project is dying, feel free to ignore this PR (I need it for my work on AsyncResources and it seems generally relevant)

The existing save/restore stack looses the reference to the actual AsyncResource - if you try to use (for example) AsyncLocalStorage - it will fail because the current asyncResource is undefined (even though the ID is).

This PR adds one more gnarly hack to these functions - to grab the existing AsyncResource then manually push it back onto the stack.

I modified the async_hooks test to check for this too. All the tests that were passing before are passing now (for some reason pool and cleanup fail for me on master).

laverdet commented 1 year ago

I love gnarly hacks. This change definitely looks more promising than the other PR. I'm not cutting more releases at this time but I'll make sure to take a note of the change in case anyone else runs into the same issues. Thank you for the contribution.