Comments (6)
Thanks for reporting this! I think the right thing to do is probably to consult the state field and complete one or the other handle, depending on whether the task should report done.
from libunifex.
@ispeters Thanks for looking at this!
I've tried out the fix but now there appears to be a race between accesses to handleToResume_
.
For example, sometimes this assertion fails (presumably because it hasn't yet been filled by the thread which observed refCount_ == 2
):
unifex/task.hpp:426: void unifex::_task::_sr_thunk_promise_base::receiver_t::set_value(bool): Assertion `self->handleToResume_ != coro::coroutine_handle<>{}' failed.
At the same time, even with one thread, I'm still getting a use-after-free in _sr_thunk_promise_base::unhandled_done()
writing to handleToResume_
.
ASAN reports that the memory was freed by the same expression inside continuation_.done()
because it ends up calling set_done()
on the task
's receiver (which in turn immediately destroys the operation state and frees the memory).
from libunifex.
Bleh. Ok. We'll have to look at this again.
What kind of scheduler are you using? Is it multithreaded?
from libunifex.
What kind of scheduler are you using? Is it multithreaded?
It is, but there's also always a main thread which is the one that cancels tasks on shutdown.
I've tried with both one and multiple worker threads - both have issues.
The execution context is a work stealing thread pool, and it doesn't react to stop requests.
Something that might be of interest is that crashes don't happen when tasks get cancelled by the stop tokens which their receivers provide (can happen during normal operation).
Problems (crashes and assertion failures) seem to only start when the cancellation originates "from inside" some async subsystem which is shutting down - a co_await
ed sender completes with set_done()
.
Sometimes a task can be cancelled both "externally" by a stop token and "internally" by set_done()
around the same time.
Since the code was written without scheduler-aware tasks (I'm currently working on upgrading libunifex
), a lot of tasks have co_await unifex::schedule(scheduler)
in them - perhaps the new "magic" handling of such cases has something to do with the issue.
So far I haven't managed to create a minimal example which exhibits the same behavior.
from libunifex.
BTW, the CPO for indexed_for
is missing inline constexpr
causing duplicate definitions.
from libunifex.
I think I have a solution for this problem, but I clearly need a unit test that captures the bug so I can be sure it's squished.
I'm thinking I add a void (*deferredStopComplete_)(_sr_thunk_promise_base*) noexcept
to _sr_thunk_promise_base
and change receiver_t::set_value
to invoke self->deferredStopComplete_(self)
when it's the last to complete.
_sr_thunk_promise
can set deferrredStopComplete_
to a static member function that can see the _return_value_or_void
base class, which means it'll be able to read the state_
member of the result_
field and will thus be able to choose which continuation to resume. When there are two operations racing to complete, the final_awaiter
's decrement of the reference count happens-after the primary operation has written the state_
so the deferredStopComplete_
implementation will be able to read it safely.
BTW, the CPO for
indexed_for
is missinginline constexpr
causing duplicate definitions.
I'll look into it.
from libunifex.
Related Issues (20)
- blocking_kind customization does not compile HOT 1
- let_value decay-copies its final result HOT 4
- Using any_object with any_scheduler
- Fix errors when syncing master back to third-party HOT 1
- How to distinguish between cancellation from stop_when and ouside?
- Improve and rename `type_erased_stream` -> `any_stream_of`
- build libunifex failed with g++ 13.1.0
- request_stop() return value is invalid
- (Is there already) support for async stream HOT 7
- How to properly use gtest dependency for building libunifex?
- Compile error with MSVC in default settings HOT 3
- Compile failed In Default Setting HOT 3
- Is there something equivalent to thread-local storage, but for coroutines? HOT 1
- /builddir/build/BUILD/libunifex-0.4.0/include/unifex/v2/async_scope.hpp:76:52: error: βMEM[(const struct scope_reference *)&optFuture].scope_β may be used uninitialized [-Werror=maybe-uninitialized]
- Add documentation for unstoppable
- Document that senders run by at_coroutine_exist must succeed
- error_types is often an invalid type for dematerialize sender HOT 1
- When will the kernel side io_uring passthrough for reading or writing NVMe SSD devices be available?
- When will the kernel side io_uring passthrough for reading or writing NVMe SSD devices be available?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libunifex.