GithubHelp home page GithubHelp logo

Comments (2)

yiyuanliu avatar yiyuanliu commented on April 28, 2024

I think this problem may be related to the following code in ViaIfAsync.h. If a task uses the default RequestContext, promise.context should be nullptr. It may be wrong to modify RequestContext here. I'm not sure about this, but after removing this logic, RequestContext remains consistent before and after co_await.

FOLLY_CORO_AWAIT_SUSPEND_NONTRIVIAL_ATTRIBUTES void await_suspend(
coroutine_handle<promise_type> h) noexcept {
auto& promise = h.promise();
if (!promise.context_) {
promise.setRequestContext(RequestContext::saveContext());
}

from folly.

yiyuanliu avatar yiyuanliu commented on April 28, 2024

I think this problem may be related to the following code in ViaIfAsync.h. If a task uses the default RequestContext, promise.context should be nullptr. It may be wrong to modify RequestContext here. I'm not sure about this, but after removing this logic, RequestContext remains consistent before and after co_await.

FOLLY_CORO_AWAIT_SUSPEND_NONTRIVIAL_ATTRIBUTES void await_suspend(
coroutine_handle<promise_type> h) noexcept {
auto& promise = h.promise();
if (!promise.context_) {
promise.setRequestContext(RequestContext::saveContext());
}

// NOTE: We are using a heuristic here to determine when is the correct
// time to capture the RequestContext. We want to capture the context just
// before the coroutine suspends and execution is returned to the executor.
//
// In cases where we are awaiting another coroutine and symmetrically
// transferring execution to another coroutine we are not yet returning
// execution to the executor so we want to defer capturing the context until
// the ViaCoroutine is resumed and suspends in final_suspend() before
// scheduling the resumption on the executor.
//
// In cases where the awaitable may suspend without transferring execution
// to another coroutine and will therefore return back to the executor we
// want to capture the execution context before calling into the wrapped
// awaitable's await_suspend() method (since it's await_suspend() method
// might schedule resumption on another thread and could resume and destroy
// the ViaCoroutine before the await_suspend() method returns).

It seems that an attempt is being made here to determine whether RequestContext needs to be saved in FinalAwaiter by checking whether promise.context_ is a null pointer. However, this approach overlooks cases where the coroutine uses the default RequestContext. In such cases, promise.context_ should be a null pointer as well. Perhaps we could modify the type of promise.context_ to optional<std::shared_ptr<RequestContext>>, so that we can differentiate between cases where RequestContext is not saved and cases where RequestContext is default.

from folly.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.