Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive cross-platform asynchronous I/O library for the bee.lua project, implementing backends for Windows (IOCP), Linux (io_uring and epoll), and macOS/BSD (GCD and kqueue). The implementation includes specialized stream buffers and Lua bindings to expose these capabilities. Critical feedback identifies a use-after-free vulnerability in the BSD backend's cancellation logic where kqueue events are not properly deregistered. Additional improvements are suggested to optimize memory usage in the macOS backend by avoiding heap allocations in poll submissions, clarify the behavior of the io_uring cancellation stub, and clean up unreachable code within the Lua binding's completion iterator.
There was a problem hiding this comment.
Pull request overview
该 PR 引入 bee.async 跨平台异步 I/O 模块,并补齐 Lua 绑定、类型注解、测试与性能对比基准,用于在 Windows/macOS/Linux/BSD 上提供统一的异步 socket / 文件 I/O / fd poll API。
Changes:
- 新增
bee.asyncLua 模块与 C++ 后端实现(Windows IOCP、macOS GCD、Linux io_uring/epoll、BSD kqueue)。 - 新增 ring buffer(readbuf)与 per-stream write buffer(writebuf)并在 Lua 侧暴露 submit/readline/backpressure 相关接口。
- 新增单元测试与 benchmark(epoll vs async),并更新 test/bench 启动脚本与构建选择开关。
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| test/test_async.lua | 新增 async 模块的功能性测试(读写/accept/connect/文件IO/poll/backpressure/close 等)。 |
| test/test.lua | 将 test_async 纳入测试入口。 |
| test.lua | 支持 -bench 路径:在 benchmark/ 下运行 bench.lua,否则运行单元测试。 |
| meta/async.lua | 新增 bee.async 的 Lua 类型注解与 API 说明。 |
| compile/common.lua | 增加可选后端选择(macOS kqueue / Linux epoll)相关的源文件排除与宏定义。 |
| binding/lua_socket.cpp | 暴露 socket fd / endpoint 的辅助函数,供 async 绑定复用。 |
| binding/lua_async.cpp | 新增 bee.async Lua 绑定:提交 I/O、completion 迭代器、readbuf/writebuf 实现。 |
| benchmark/net_epoll.lua | 新增 epoll 版网络抽象用于性能对比。 |
| benchmark/net_async.lua | 新增 async 版网络抽象用于性能对比。 |
| benchmark/ltask.lua | 新增轻量任务调度器(用于 benchmark 驱动)。 |
| benchmark/bench.lua | 新增基准:epoll/async × rtt/pipeline 对比。 |
| bee/async/write_buf.h | 新增 writebuf 数据结构(队列、HWM、in-flight 状态)。 |
| bee/async/ring_buf.h | 新增 ring buffer(readbuf)实现:commit/consume/find/readline 支持。 |
| bee/async/async_win.h | 新增 Windows IOCP 后端接口声明(含文件/accept/connect/poll 等)。 |
| bee/async/async_win.cpp | 新增 Windows IOCP 后端实现(AcceptEx/ConnectEx、同步完成队列等)。 |
| bee/async/async_uring_linux.h | 新增 Linux io_uring 后端声明。 |
| bee/async/async_uring_linux.cpp | 新增 Linux io_uring 后端实现(自带 UAPI 定义、mmap ring、submit/harvest)。 |
| bee/async/async_types.h | 新增跨后端统一的 completion 状态/操作类型定义。 |
| bee/async/async_osx.h | 新增 macOS GCD 后端声明(dispatch source + semaphore)。 |
| bee/async/async_osx.cpp | 新增 macOS GCD 后端实现(按 fd 复用 read/write source + one-shot accept/connect/poll)。 |
| bee/async/async_epoll_linux.h | 新增 Linux epoll 后端声明(fd_state + pending_op)。 |
| bee/async/async_epoll_linux.cpp | 新增 Linux epoll 后端实现(arm/disarm、event drain、sync completions)。 |
| bee/async/async_bsd.h | 新增 BSD kqueue 后端声明(pending_op set + kevent 注册)。 |
| bee/async/async_bsd.cpp | 新增 BSD kqueue 后端实现(EV_ONESHOT、drain、cancel/stop)。 |
| bee/async/async.h | 新增跨平台 async 抽象与平台选择 include。 |
| bee/async/async.cpp | 新增后端工厂:Linux 优先 io_uring,不可用则回退 epoll;其他平台创建对应实现。 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…le_read completions Agent-Logs-Url: https://github.com/actboy168/bee.lua/sessions/27a22d9e-eaf9-4907-a4c1-00bc1f532a4c Co-authored-by: actboy168 <1836844+actboy168@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a cross-platform asynchronous I/O library for the Bee project, supporting Linux (io_uring/epoll), macOS (GCD), and Windows (IOCP). The implementation includes core async interfaces, platform-specific backends, and Lua bindings. My review identified several critical issues: a use-after-free vulnerability in file writing due to missing Lua object pinning, potential infinite loops in write completion handling across multiple backends, memory leaks in the Lua completion iterator, and a potential deadlock scenario when cancelling I/O operations.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 26 out of 26 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 28 out of 28 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements a cross-platform asynchronous I/O library for Lua, providing backends for Windows (IOCP), Linux (io_uring/epoll), and macOS/BSD (GCD/kqueue). The review identified a critical memory safety bug in the Windows backend where stack-allocated WSABUF structures are used for asynchronous operations. Additionally, the cancel implementation across multiple platforms needs to generate completion events to avoid leaking Lua references. Other feedback includes a request for functional cancellation in the io_uring backend and a minor formatting correction.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 28 out of 28 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.