Skip to content

[libcxx] copy_file enters an infinite loop in a multithreaded environment. #169261

@Costatie

Description

@Costatie

When I use multiple threads to copy a file without locking, there are occasional instances where the copy_file operation seems to get stuck indefinitely.
By adding print logs before and after calling copy_file, it was discovered that the process was getting stuck during the call to copy_file_impl_copy_file_range.The main body of copy_file_impl_copy_file_range is a loop.

  do {
    ssize_t res;

    if ((res = ::copy_file_range(read_fd.fd, &off_in, write_fd.fd, &off_out, count, 0)) == -1) {
      ec = capture_errno();
      return false;
    }
    count -= res;
  } while (count > 0);

In the above scenario, the value of res was returned as 0. It appears that one of the two threads was continuously copying empty data.Why does this situation occur? Should we add a condition to check if res is 0 to prevent entering an infinite loop?

Metadata

Metadata

Assignees

No one assigned

    Labels

    filesystemC++17 std::filesystemlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions