Code Monkey home page Code Monkey logo

asyncio's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

asyncio's Issues

在取消 Buffer drain 任务时可能造成的 crash

asyncio/src/ev/buffer.cpp

Lines 272 to 282 in e650d90

co_return co_await zero::async::coroutine::Cancellable{
zero::async::promise::chain<void, std::error_code>([this](const auto &promise) {
mPromises[DRAIN_INDEX] = promise;
}),
[this]() -> tl::expected<void, std::error_code> {
std::exchange(mPromises[DRAIN_INDEX], std::nullopt)->reject(
make_error_code(std::errc::operation_canceled)
);
return {};
}
};

有一种场景是使用 asyncio::copy 进行转发:

co_await zero::async::coroutine::race(asyncio::copy(local, remote), asyncio::copy(remote, local));

当任务 asyncio::copy(local, remote)local->read 挂起,asyncio::copy(remote, local)local->drain 挂起时,local 触发了关闭事件,由于 promise 现在是线性处理的:

asyncio/src/ev/buffer.cpp

Lines 428 to 449 in e650d90

void asyncio::ev::Buffer::onClose(const std::error_code &ec) {
mClosed = true;
mLastError = ec;
auto [read, drain, waitClosed] = std::exchange(mPromises, {});
if (read)
read->reject(ec);
if (drain)
drain->reject(ec);
if (!waitClosed)
return;
if (ec != Error::IO_EOF) {
waitClosed->reject(ec);
return;
}
waitClosed->resolve();
}

所以任务 asyncio::copy(local, remote) 首先由于 read promise 被拒绝而结束,但是此时 drain promise 还是 pending 状态。然后 race 尝试取消 asyncio::copy(remote, local),但是此时 mPromises[DRAIN_INDEX] 已经为空了。

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.