Skip to content
This repository was archived by the owner on Mar 31, 2018. It is now read-only.
This repository was archived by the owner on Mar 31, 2018. It is now read-only.

Async/Await implementation in V8 #4

Closed

Description

@benjamingr

Async await is coming our way with v8 slated to implement it in Q2 2016.

Node needs to be prepared :)

Possible areas of impact:

  • V8's implementation needs to be tracked so we make sure we have our right hooks when it lands. Things like unhandledRejection might possibly be impacted as well as the way promises are currently queued and run in Node.
  • We need to consider the whole operational vs. programmer error issue here.
  • Core dumps should work properly in async methods.

Probably many others, just starting the discussion.

Activity

  1. chrisdickinson commented on Feb 15, 2016

    @chrisdickinson
    Contributor

    This issue is a bit open-ended. Would you mind scoping it in, or closing it if it can't be scoped in?

  2. petkaantonov commented on Feb 15, 2016

    @petkaantonov
    Contributor

    Core dumps should work properly in async methods.

    This is discussed in #8 , (point 2. in OP)

  3. benjamingr commented on Feb 15, 2016

    @benjamingr
    MemberAuthor

    Basically - to track https://bugs.chromium.org/p/v8/issues/detail?id=4483 and make sure we're keeping up with the implementation from the node side and until then to discuss desirable behavior we'd like async functions to have in Node. Namely that none of the hooks (unhandledRejection, rejectionHandled) break.

    This is non-blocking for the promises-in-core PR just so we're clear. I'll scope it in.

  4. changed the title [-]Async/Await[/-] [+]Async/Await implementation in V8[/+] on Feb 15, 2016
  5. benjamingr commented on Feb 15, 2016

    @benjamingr
    MemberAuthor

    I changed the name is this better @chrisdickinson ?

  6. chrisdickinson commented on Feb 15, 2016

    @chrisdickinson
    Contributor

    Excellent, thank you!

  7. littledan commented on Feb 16, 2016

    @littledan

    To clarify, V8 intends to implement async/await but we don't have any particular schedule announced. async/await is a lot like using Promises directly. I'm not sure if anything special is needed for Node's needs here. But if there are other requirements, I'd really like to hear about them. About the points here:

    • Unhandled rejections will be handled, according to the spec, just like Promise unhandled rejections, and invoke the handlers as appropriate.
    • For operational/programmer errors, I like the idea of a convention to either return some kind of error code or passing an error callback as opposed to using Promise rejection within Node. Promise rejection is equivalent to throwing an exception, and async/await makes this very clear, so if exceptions are to be avoided in Node, then error callbacks or codes would work better.
    • For core dumps, seems like the important thing is that the unhandled rejection callback can do a core dump. Does anyone know if there are any issues with these callbacks and core dumps at the moment? I don't see async/await changing a lot about them here vs how things are today with Promises.
  8. petkaantonov commented on Feb 16, 2016

    @petkaantonov
    Contributor

    @littledan

    Errors with promise users are always through one channel even in node and any exceptions node tries to throw for promise users can be caught or listened with domains and turned into rejections. This way the consumer decides whether an error is operational/programmer error because the producer of the error simply cannot know this. Adding additional error channel doesn't add value to this as it is the producer who will choose the channel at error production time and therefore the consumer would be forced to duplicate code for the different channels. There are plenty of examples how the same error can be programmer error and operational error depending on what the consumer is doing.

    Glossary:

    • producer means producer of the error
    • consumer means consumer of the error
  9. chrisdickinson commented on Feb 16, 2016

    @chrisdickinson
    Contributor

    @littledan There are two problems with core dumps and promises at present:

    1. Unhandled rejection at the end of a chain — that is, rejectAPromise().then(A).then(B).then(C) will catch and rethrow the error three times, and the abort will happen at C's PromiseIdRejectHandler, instead at the source of the rejection in rejectAPromise as desired. @misterdjules has some work put towards this — primarily around running handlers and executors without try / catch if a --abort-on-uncaught-exception flag is set and PromiseHasUserDefinedRejectHandler is false.
    2. (This is primarily on the Node end, but!) Right now we wait until the end of the microtask queue to fire the unhandledRejection listener, so that we can check that the promises rejected during microtask execution have not been synchronously handled. This means that we have to unwind the stack, which produces less useful cores. We may be able to switch our behavior using flags here, but it means all synchronous rejections will immediately abort the program (i.e., we may have to patch Promise.reject to return a pending promise that rejects on next tick instead of immediately.)
  10. petkaantonov commented on Feb 16, 2016

    @petkaantonov
    Contributor

    The stack can be saved and restored later like. Chrome has to do something like this for the async debugger to work. Theoretically the mutable objects that a stack points to might have been destructively changed but there is a high chance this isn't a practical concern.

  11. benjamingr commented on Feb 16, 2016

    @benjamingr
    MemberAuthor

    @littledan like @petkaantonov and @chrisdickinson said - any help with porting the async stack traces like functionality to node that would allow us to save and restore the stack for inspection would be greatly appreciated.

    Clarification: The feature in Chrome is called async stack traces but it actually saves the actual stack and not just the trace.

  12. benjamingr commented on Feb 16, 2016

    @benjamingr
    MemberAuthor

    @CrabDude Awesome. That would be great!

    I think the first step is to figure out and map how Chrome's async stack traces feature works - how we can keep track of the stack, this value and arguments and how things work.

    This post contains the PRs node-inspector/node-inspector#340

    The challenging part isn't just getting the trace - it's getting the stack frame - in the devtools I can access the closure variables, this value and more. If we can produce and then consume similar output that would be awesome for debugging.

    Here is an HTML5Rocks article about how to use the feature in case you are not already familiar http://www.html5rocks.com/en/tutorials/developertools/async-call-stack/

  13. benjamingr commented on Feb 21, 2016

    @benjamingr
    MemberAuthor

    @CrabDude any progress? Anything you need help with?

  14. 44 remaining items

  15. ofrobots commented on Oct 25, 2016

    @ofrobots

    That is not a release announcement. 'V8 5.5 has branched and this is what
    it contains'
    On Tue, Oct 25, 2016 at 5:28 AM Piero notifications@github.com wrote:

    V8 55 released:
    http://v8project.blogspot.com.br/2016/10/v8-release-55.html

    —
    You are receiving this because you commented.

    Reply to this email directly, view it on GitHub
    #4 (comment), or mute
    the thread
    https://github.com/notifications/unsubscribe-auth/AAE0qbLdoPmHglDCL4jyP2wL1MB0qyGVks5q3fXTgaJpZM4Hahze
    .

  16. chrisveness commented on Oct 25, 2016

    @chrisveness

    ... "will be in beta until it is released in coordination with Chrome 55 Stable in several weeks"

  17. rvagg commented on Oct 30, 2016

    @rvagg
    Member

    While a mid-stream, ABI-neutral upgrade to V8 5.5 is theoretically possible on the Node.js v7.x branch, I personally think that we should hold off until promise hook support is available in V8 (i.e. until Node.js v8.x).

    Can you clarify this a little more @ofrobots? I've been working under the assumption that a 5.5 mid-current wouldn't be a big deal, are you thinking that our lack of ability to interact properly with Promise internals should hold that back because of how widely async/await will be adopted?

  18. leodutra commented on Oct 30, 2016

    @leodutra

    I have another worry about this. I can't stop thinking how nice would be
    each promisse running in a libuv thread. I don't know if it is implemented
    this way today, but if the cost of these threads are cheap... Maybe using
    stream internally to run the hidden promise resolutions could make node
    even more powerful.

    It's the point of view of a passing guy, MHO.

  19. ljharb commented on Oct 30, 2016

    @ljharb
    SponsorMember

    @leodutra it would have to be unobservable to the underlying JS to be spec-compliant - JS is single-threaded.

  20. leodutra commented on Oct 30, 2016

    @leodutra
  21. ljharb commented on Oct 30, 2016

    @ljharb
    SponsorMember

    @leodutra that's certainly one opinion. There's quite a number of people, like myself, who consider threading a legacy programming model. None the less, this is the way JS is and will stay.

  22. nickserv commented on Nov 1, 2016

    @nickserv

    Also, isn't the async/await implementation still using Promises or something similar internally? If so, Promises have already been stable in V8/Node, so I see less risk in pushing prereleases with async/await support.

  23. adnan-kamili commented on Dec 2, 2016

    @adnan-kamili

    Chrome 55 stable is out, @littledan are there any API breaking changes, if no can we expect it to part of next Node.js 7.x release and get rid of harmony flag for async await

  24. billinghamj commented on Dec 3, 2016

    @billinghamj

    @adnan-kamili The breaking changes would be at the native API level, and there almost certainly are some. Unfortunately this is unlikely before Node v8 :(

  25. ofrobots commented on Dec 5, 2016

    @ofrobots

    You can track the status of the effort to integrate V8 5.5 here: nodejs/node#9618

  26. billinghamj commented on Dec 6, 2016

    @billinghamj

    nodejs/node#9618 (comment) - so should be coming to v7 :)

  27. AMorgaut commented on Dec 21, 2016

    @AMorgaut

    @nickmccurdy async functions are also based internally on generators, so they also need them to be stable, not just the Promises. But I think that's the case ;-)

  28. adnan-kamili commented on Feb 1, 2017

    @adnan-kamili

    Issue tracking the backport of v8 5.5 into 7.x branch

    nodejs/node#11029

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions