Skip to content

coroutine: add Coroutine::AsyncQueue and immediate evaluation support in LeafAwaitable - #46885

Open
penguingao wants to merge 39 commits into
envoyproxy:mainfrom
penguingao:coroutine_async_queue_jetski
Open

coroutine: add Coroutine::AsyncQueue and immediate evaluation support in LeafAwaitable#46885
penguingao wants to merge 39 commits into
envoyproxy:mainfrom
penguingao:coroutine_async_queue_jetski

Conversation

@penguingao

@penguingao penguingao commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Commit Message:
Add a Coroutine::AsyncQueue implementation. This is a useful utility to pass buffer / items among coroutines. Immediate use case is in APM's AI filter manager implementation that's forthcoming in a next PR.

AsyncQueue::push and AsyncQueue::pop can be used with co_await. Non-blocking methods are available.

The implementation can share capacity among multiple instances. It's typical for a buffer to be passed in a chain of queues, and we'd like the total bytes in the queues to be bound in size. Bounding the memory usage in queue is to mirror what callback based filter chains do with buffer watermark callbacks.

Semaphore was created as I work on this and realized that it's a generally useful abstract. Happy to split if that's easier for review. Semaphore is very much a standard thing for most coroutine libraries. When STL has it, it should be fairly trivial to replace it with a std version. Same way as Coroutine::Task and Scheduler. AsyncQueue would be probably an Envoy specific thing.

I used AI to generate this PR. I have read the code and understand it.

Additional Description:
Risk Level: low - new utility
Testing: unit tests
Docs Changes: N/A - internal utility
Release Notes: N/A - internal utility
Platform Specific Features: no

@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #46885 was opened by penguingao.

see: more, trace.

…itable

Signed-off-by: Peng Gao <pengg@google.com>
…yncQueue

Signed-off-by: Peng Gao <pengg@google.com>
…haring issues in AsyncQueue

Signed-off-by: Peng Gao <pengg@google.com>
@penguingao
penguingao force-pushed the coroutine_async_queue_jetski branch from b92c22e to 1b43a77 Compare August 22, 2026 13:11
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Implements AsyncQueue and SharedCapacity using coroutine async primitives (AsyncEvent),
providing FIFO async channels, bounded capacity management, move-only type support,
and direct handoff semantics.

Signed-off via git commit -s.

Signed-off-by: Peng Gao <pengg@google.com>
…ere appropriate

Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
…_jetski

Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
@penguingao

Copy link
Copy Markdown
Contributor Author

/retest

Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
This reverts commit 7a9abb9.

Signed-off-by: Peng Gao <pengg@google.com>
…ferences

Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
…tests

Avoid immediately-invoked lambda coroutines with captures in
AsyncQueueTest and SemaphoreTest to prevent stack-use-after-scope
under ASan. Pass Semaphore by reference to coroutine task in
DestructionWhileProcessWaitersScheduled so the test retains sole
ownership of the Semaphore shared_ptr.

TAG=agy
CONV=1167748b-3e90-4d8d-8e9c-4f141b6cbdd2

Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
…elease private

Signed-off-by: Peng Gao <pengg@google.com>
Signed-off-by: Peng Gao <pengg@google.com>
@penguingao
penguingao marked this pull request as ready for review August 25, 2026 15:01
@penguingao

Copy link
Copy Markdown
Contributor Author

/assign @botengyao @tyxia

Signed-off-by: Peng Gao <pengg@google.com>
@penguingao

Copy link
Copy Markdown
Contributor Author

@penguingao

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@penguingao

Copy link
Copy Markdown
Contributor Author

/retest

Signed-off-by: Peng Gao <pengg@google.com>
@penguingao

Copy link
Copy Markdown
Contributor Author

/retest

@botengyao botengyao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks great! thanks!

/wait

Comment thread source/common/coroutine/semaphore.h
@penguingao

Copy link
Copy Markdown
Contributor Author

Thanks for the view! I addressed the comment.

@botengyao botengyao removed the waiting label Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants