Skip to content

Conversation

avikivity
Copy link
Member

Mostly improving readability.

thread_pool::submit() will yield, so we lose nothing by
converting to a coroutine, and gain some readability.
file_stat() will yield, so we lose nothing by
converting to a coroutine, and gain some readability.
thread_pool::submit() will yield, so we lose nothing by
converting to a coroutine, and gain some readability.
thread_pool::submit() will yield, so we lose nothing by
converting to a coroutine, and gain some readability.
thread_pool::submit() will yield, so we lose nothing by
converting to a coroutine, and gain some readability.
thread_pool::submit() will yield, so we lose nothing by
converting to a coroutine, and gain some readability.
thread_pool::submit() will yield, so we lose nothing by
converting to a coroutine, and gain some readability.
thread_pool::submit() will yield, so we lose nothing by
converting to a coroutine, and gain some readability.
thread_pool::submit() will yield, so we lose nothing by
converting to a coroutine, and gain some readability.
thread_pool::submit() (or waiting for the aio backend) will yield, so
we lose nothing by converting to a coroutine, and gain some readability.
@avikivity avikivity requested a review from Copilot August 3, 2025 13:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR converts several file-related functions in the reactor class from using callback-based futures to coroutines (co_await/co_return), improving code readability and reducing nesting complexity.

  • Eliminates nested .then() chains in favor of linear coroutine syntax
  • Removes redundant futurize_invoke wrapper calls
  • Simplifies error handling flow in asynchronous file operations

reactor::file_stat(std::string_view pathname_view, follow_symlink follow) noexcept {
auto pathname = sstring(pathname_view);
syscall_result_extra<struct stat> sr = co_await _thread_pool->submit<syscall_result_extra<struct stat>>(
internal::thread_pool_submit_reason::file_operation, [&] {
Copy link
Preview

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

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

The lambda captures the pathname variable by reference, but the lambda will be executed asynchronously in a thread pool after the current function scope may have ended. This creates a dangling reference. The original code correctly captured by value with [pathname = sstring(pathname), follow].

Suggested change
internal::thread_pool_submit_reason::file_operation, [&] {
internal::thread_pool_submit_reason::file_operation, [pathname = std::move(pathname), follow] {

Copilot uses AI. Check for mistakes.

reactor::file_accessible(std::string_view pathname_view, access_flags flags) noexcept {
auto pathname = sstring(pathname_view);
syscall_result<int> sr = co_await _thread_pool->submit<syscall_result<int>>(
internal::thread_pool_submit_reason::file_operation, [&] {
Copy link
Preview

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

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

The lambda captures variables by reference, but the lambda will be executed asynchronously in a thread pool. This creates dangling references to pathname and flags. The original code correctly captured by value.

Suggested change
internal::thread_pool_submit_reason::file_operation, [&] {
internal::thread_pool_submit_reason::file_operation, [pathname, flags] {

Copilot uses AI. Check for mistakes.

reactor::file_system_at(std::string_view pathname_view) noexcept {
auto pathname = sstring(pathname_view);
syscall_result_extra<struct statfs> sr = co_await _thread_pool->submit<syscall_result_extra<struct statfs>>(
internal::thread_pool_submit_reason::file_operation, [&] {
Copy link
Preview

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

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

The lambda captures the pathname variable by reference, but the lambda will be executed asynchronously in a thread pool. This creates a dangling reference. The original code correctly captured by value.

Suggested change
internal::thread_pool_submit_reason::file_operation, [&] {
internal::thread_pool_submit_reason::file_operation, [pathname] {

Copilot uses AI. Check for mistakes.

reactor::statvfs(std::string_view pathname_view) noexcept {
auto pathname = sstring(pathname_view);
syscall_result_extra<struct statvfs> sr = co_await _thread_pool->submit<syscall_result_extra<struct statvfs>>(
internal::thread_pool_submit_reason::file_operation, [&] {
Copy link
Preview

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

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

The lambda captures the pathname variable by reference, but the lambda will be executed asynchronously in a thread pool. This creates a dangling reference. The original code correctly captured by value.

Suggested change
internal::thread_pool_submit_reason::file_operation, [&] {
internal::thread_pool_submit_reason::file_operation, [pathname] {

Copilot uses AI. Check for mistakes.

auto name = sstring(name_view);
auto oflags = O_DIRECTORY | O_CLOEXEC | O_RDONLY;
syscall_result_extra<struct stat> sr = co_await _thread_pool->submit<syscall_result_extra<struct stat>>(
internal::thread_pool_submit_reason::file_operation, [&] {
Copy link
Preview

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

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

The lambda captures variables by reference, but the lambda will be executed asynchronously in a thread pool. This creates dangling references to name and oflags. The original code correctly captured by value.

Suggested change
internal::thread_pool_submit_reason::file_operation, [&] {
internal::thread_pool_submit_reason::file_operation, [name, oflags] {

Copilot uses AI. Check for mistakes.

reactor::make_directory(std::string_view name_view, file_permissions permissions) noexcept {
auto name = sstring(name_view);
syscall_result<int> sr = co_await _thread_pool->submit<syscall_result<int>>(
internal::thread_pool_submit_reason::file_operation, [&] {
Copy link
Preview

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

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

The lambda captures variables by reference, but the lambda will be executed asynchronously in a thread pool. This creates dangling references to name and permissions. The original code correctly captured by value.

Suggested change
internal::thread_pool_submit_reason::file_operation, [&] {
internal::thread_pool_submit_reason::file_operation, [name, permissions] {

Copilot uses AI. Check for mistakes.

reactor::touch_directory(std::string_view name_view, file_permissions permissions) noexcept {
auto name = sstring(name_view);
syscall_result<int> sr = co_await _thread_pool->submit<syscall_result<int>>(
internal::thread_pool_submit_reason::file_operation, [&] {
Copy link
Preview

Copilot AI Aug 3, 2025

Choose a reason for hiding this comment

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

The lambda captures variables by reference, but the lambda will be executed asynchronously in a thread pool. This creates dangling references to name and permissions. The original code correctly captured by value.

Suggested change
internal::thread_pool_submit_reason::file_operation, [&] {
internal::thread_pool_submit_reason::file_operation, [name, permissions] {

Copilot uses AI. Check for mistakes.

@avikivity
Copy link
Member Author

The problem is that coroutine allocation doesn't disable memory failure injection while allocating the coroutine frame (as we do when allocating a continuation).

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.

1 participant